Skip to content

🐛(backend) read waffle flags by their name so the cache is flushed - #3062

Open
sanketpatel32 wants to merge 1 commit into
suitenumerique:mainfrom
sanketpatel32:devin/2975-waffle-strenum
Open

sanketpatel32 wants to merge 1 commit into
suitenumerique:mainfrom
sanketpatel32:devin/2975-waffle-strenum

Conversation

@sanketpatel32

Copy link
Copy Markdown

Purpose

Fixes #2975.

FeatureFlag was a (str, Enum) mixin, so str(member) returned "FeatureFlag.FLAG_X" instead of the flag name. django-waffle keys its Flag rows and its cache entries on str(name), so reads and the cache flushes on flag saves never matched: the first read answer stayed cached forever and flag updates from the admin never took effect.

Proposal

  • Make FeatureFlag a StrEnum so str(member) is the flag name.
  • Regression tests: a flag saved under its plain name is seen through the enum, and a flag save flushes the previously cached read.

External contributions

General requirements

CI requirements

  • I made sure that all existing tests are passing
  • I have signed off my commits with git commit --signoff (DCO compliance)
  • I have signed my commits with my SSH or GPG key (git commit -S) — no signing key is available in this environment; let me know if it is required and I will arrange it
  • My commit messages follow the required format: <gitmoji>(type) title description
  • I have added a changelog entry under ## [Unreleased] section (if noticeable change)

AI requirements

  • I used AI assistance to produce part or all of this contribution (Devin, on behalf of Sanket Patel)
  • I have read, reviewed, understood and can explain the code I am submitting
  • I can jump in a call or a chat to explain my work to a maintainer

FeatureFlag was a (str, Enum) mixin, so str(member) returned
"FeatureFlag.FLAG_X" instead of the flag name. django-waffle keys its
Flag rows and its cache entries on str(name), so the reads and the cache
flushes happening on flag saves never matched: the first read answer
stayed cached forever and flag updates from the admin never took effect.

Making FeatureFlag a StrEnum makes str(member) the flag name again,
matching every Flag row and cache entry.

Refs suitenumerique#2975

Signed-off-by: Sanket Patel <sanpatel323@gmail.com>
@coderabbitai

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

FeatureFlag now subclasses StrEnum, so its string form uses the flag value. New tests check flag lookup by that value and verify that a saved flag change is visible on a subsequent request after the cache flush. The Unreleased changelog records the fix.

Estimated code review effort: 2 (Simple) | ~10 minutes

Severity of issue fixed: Medium

Suggested reviewers: mascarpon3, lunika

Merge Risk: Minimal · up to 8090a

This fix makes feature-flag changes visible immediately instead of after the cache entry expires. The change is small and confined to the enum, with regression tests. There is no identified merge-blocking risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: FeatureFlag reads now use the flag name so the waffle cache is flushed. The raw summary confirms the enum change to StrEnum, which makes str(member) return the flag n…
Description check Passed The description states the purpose (fixing #2975), explains that FeatureFlag was a (str, Enum) mixin whose str() output did not match django-waffle's flag names, and lists the StrEnum change and regre…
Linked Issues check Passed [#2975] The issue asks for two coding changes: (1) make FeatureFlag a StrEnum so str(member) is the flag name, and (2) add a test that a flag changed after a first flag_is_active read is seen at once.…
Out of Scope Changes check Passed The whole-PR changes are limited to three files: the CHANGELOG.md entry for #2975, the FeatureFlag base-class change and docstring in src/backend/core/enums.py, and the two regression tests added to t…
Full details: Title check

Explanation

The title states the main change: FeatureFlag reads now use the flag name so the waffle cache is flushed. The raw summary confirms the enum change to StrEnum, which makes str(member) return the flag name, and the related regression tests. The title uses an emoji prefix, which is the project's commit convention and does not make it unclear.

Full details: Description check

Explanation

The description states the purpose (fixing #2975), explains that FeatureFlag was a (str, Enum) mixin whose str() output did not match django-waffle's flag names, and lists the StrEnum change and regression tests. This matches the changeset.

Full details: Linked Issues check

Explanation

[#2975] The issue asks for two coding changes: (1) make FeatureFlag a StrEnum so str(member) is the flag name, and (2) add a test that a flag changed after a first flag_is_active read is seen at once. At head, src/backend/core/enums.py defines class FeatureFlag(StrEnum), so str(member) returns the value, which matches the plain name keyed by django-waffle. StrEnum is already imported and used in this module (DocumentAttachmentStatus), so the Python version supports it. In src/backend/core/tests/documents/test_api_documents_search_feature_flag.py, test_feature_flag_matches_the_flag_saved_under_its_plain_name covers the plain-name read. test_feature_flag_update_flushes_the_cached_read reads the flag once (False, cached), saves a Flag row under the plain name, and reads again (True), with transaction=True so waffle's on_commit cache flush runs. This covers the stale-cache scenario in the issue. One deviation: the issue suggests using override_flag; the test uses Flag.objects.create instead. The issue describes this as a suggested test, and the save-and-flush path is the behavior under test, so this does not fail the requirement. Test results were not run; the evidence is source inspection only.

Full details: Out of Scope Changes check

Explanation

The whole-PR changes are limited to three files: the CHANGELOG.md entry for #2975, the FeatureFlag base-class change and docstring in src/backend/core/enums.py, and the two regression tests added to test_api_documents_search_feature_flag.py. The changelog entry and the tests support the fix. The enum docstring explains the StrEnum reason. Member names and values are unchanged, so no unrelated behavior changes were found.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: e450b070-cfb6-419a-89f5-ddd94e2959b2
Commits

Reviewing files that changed from the base of the PR and between 5b55459 and 8090aff.

Files selected for processing: 3

  • CHANGELOG.md
  • src/backend/core/enums.py
  • src/backend/core/tests/documents/test_api_documents_search_feature_flag.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

@lunika
lunika self-requested a review November 24, 2026 16:25
@lunika lunika added the backend label Nov 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛(Bug) Waffle never flushes the cached feature flags read through FeatureFlag

2 participants