Skip to content

feat: bridge FEATURES proxy reads to @override_settings overrides#38818

Merged
feanil merged 1 commit into
masterfrom
feanil/features-dict-bridge
Jul 9, 2026
Merged

feat: bridge FEATURES proxy reads to @override_settings overrides#38818
feanil merged 1 commit into
masterfrom
feanil/features-dict-bridge

Conversation

@feanil

@feanil feanil commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

First PR in a 3-PR stack that migrates callers off of settings.FEATURES['X'] access. Follow-on to #38771.

This PR adds a single bridge to FeaturesProxy so that settings.FEATURES.get('X') walks the UserSettingsHolder chain — i.e. an @override_settings(X=...) decorator on the new flat setting is visible to legacy callers that still read the FEATURES dict. This lets us migrate call sites incrementally (#38772) without breaking unmigrated tests.

Stack:

@kdmccormick kdmccormick left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One suggestion, non-blocking

"""Store the namespace (as a dict)"""
self.ns = namespace or {}

_MISSING = object()

@kdmccormick kdmccormick Jul 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_MISSING = object()
_NOT_OVERRIDDEN = object()

I think this might make the system more self-explanatory. On my initial review I thought _MISSING was a sentinel for something that's missing from settings entirely.

Lets @override_settings(KEY=val) be seen through both settings.KEY
and settings.FEATURES['KEY']/.get('KEY'), so tests can migrate to
the flat setting without first updating every production reader
that still does settings.FEATURES['KEY'].

We walk only the UserSettingsHolder chain that @override_settings
pushes onto django.conf.settings._wrapped, NOT the bottom Settings
layer. Django's bottom Settings is a *snapshot* of the settings
module's globals taken at init time, so it doesn't reflect runtime
mutations of the module's globals — which is exactly what legacy
patch.dict(settings.FEATURES, ...) does via proxy.ns. Reading the
snapshot would mask those mutations and break legacy tests; walking
only the explicit override layers lets both paths coexist during
the migration.

ns kept as-is. A stateless redesign (drop ns, route everything
through django.conf.settings, set FEATURES = FeaturesProxy() in
each env file) was considered but rejected for this step because
FEATURES.copy() and __iter__ are widely used to snapshot the full
set of feature flags; without ns there is no clean source of truth
for "which keys are features". Once all callers have moved off the
dict pattern the proxy can be deleted outright (every
settings.FEATURES['X'] becomes settings.X), making the stateless
refactor unnecessary.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@feanil feanil force-pushed the feanil/features-dict-bridge branch from 3a686d6 to 1299ef1 Compare July 9, 2026 13:57
@feanil feanil enabled auto-merge (rebase) July 9, 2026 14:04
@feanil feanil merged commit 3366c89 into master Jul 9, 2026
45 checks passed
@feanil feanil deleted the feanil/features-dict-bridge branch July 9, 2026 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants