Fixed latent none return bug #658
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 408 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.360
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #658"
general
weight: 0.35
Mogost
Fix
mgetreturningNoneand standardize return type todictProblem
As discussed in #656, all four
mgetimplementations returnedNone(either explicitly or via barereturn) when called with an empty keys argument, violating the base class contract which specified "return an empty list if not found." Every call site wrappedmgetwithdict(...), which would raiseTypeError: cannot convert 'NoneType' object to dictif the key set was ever empty.Why this wasn't caught
The existing tests were misconfigured and actively validated the broken behavior rather than catching it.
test_mget_empty_keysin the Redis backends usedlist(... or [])to defensively work around theNonereturn, and the memory backend test explicitly assertedassertIsNone(result)— treating the bug as expected behavior. This meant the test suite passed while the underlying contract violation went undetected.Affected call sites
constance/utils.py—get_values()andget_values_for_keys()both calleddict(config._backend.mget(...)), which would crash on empty configconstance/backends/database.py—autofill()iterated directly overself.mget(...), which would crash onNoneconstance/admin.py—changelist_view()callsget_values(), propagating the crash to the admin UItests/storage.py— wrappedmgetwithdict(), masking the bug in normal test runsFix
Standardize
mgetto return adictacross all backends, matching the existingamgetcontract:DatabaseBackend.mget— builds and returns adictinstead of yielding tuples; returns{}for empty keysRedisBackend.mget— returns a dict comprehension instead of yielding tuples; returns{}for empty keysCachingRedisBackend.mget— builds and returns adictinstead of yielding tuples; returns{}for empty keysMemoryBackend.mget— returns a dict comprehension instead of a list of tuples /None; returns{}for empty keysBackendABC — updatedmget/amgetdocstrings to specifydictreturn typeconstance/utils.py— removed redundantdict()wrapping aroundmget()callsdict()wrapping andor []workarounds; fixed assertions that validated the broken behavior (assertIsNone→assertEqual(result, {}))Backwards compatibility
This changes the return type of
mgetfrom a generator/list of(key, value)tuples to adict. Code that iterates overmget()directly (e.g.for key, value in backend.mget(keys)) will break, as iterating adictyields only keys. Such call sites need to be updated to use.items(). However,mgetis a backend-internal method — the public API isconfig.SOME_KEYand theget_values()/get_values_for_keys()utility functions, none of which are affected. Potential customBackendsubclasses that overridemgetwill need to be updated to return adict. I believe that this has a very low likelihood of breaking anything downstream because user who patch backend-internal methods should pin their versions and not update packages without validating whether their change still works anyway.Please let me know your thoughts on this @camilonova and @Mogost.