← Back to Pull requests

Fixed latent none return bug #658

Closed
unknown closed this pull request without merging on Mar 11, 2026 14:58 UTC
View on GitHub
unknown unknown commented on Mar 05, 2026 08:22 UTC
Author

Fix mget returning None and standardize return type to dict

Problem

As discussed in #656, all four mget implementations returned None (either explicitly or via bare return) when called with an empty keys argument, violating the base class contract which specified "return an empty list if not found." Every call site wrapped mget with dict(...), which would raise TypeError: cannot convert 'NoneType' object to dict if 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_keys in the Redis backends used list(... or []) to defensively work around the None return, and the memory backend test explicitly asserted assertIsNone(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() and get_values_for_keys() both called dict(config._backend.mget(...)), which would crash on empty config

  • constance/backends/database.py — autofill() iterated directly over self.mget(...), which would crash on None

  • constance/admin.py — changelist_view() calls get_values(), propagating the crash to the admin UI

  • tests/storage.py — wrapped mget with dict(), masking the bug in normal test runs

  • Fix

  • Standardize mget to return a dict across all backends, matching the existing amget contract:

  • DatabaseBackend.mget — builds and returns a dict instead of yielding tuples; returns {} for empty keys

  • RedisBackend.mget — returns a dict comprehension instead of yielding tuples; returns {} for empty keys

  • CachingRedisBackend.mget — builds and returns a dict instead of yielding tuples; returns {} for empty keys

  • MemoryBackend.mget — returns a dict comprehension instead of a list of tuples / None; returns {} for empty keys

  • Backend ABC — updated mget/amget docstrings to specify dict return type

  • constance/utils.py — removed redundant dict() wrapping around mget() calls

  • Tests — removed dict() wrapping and or [] workarounds; fixed assertions that validated the broken behavior (assertIsNone → assertEqual(result, {}))
  • Backwards compatibility

    This changes the return type of mget from a generator/list of (key, value) tuples to a dict. Code that iterates over mget() directly (e.g. for key, value in backend.mget(keys)) will break, as iterating a dict yields only keys. Such call sites need to be updated to use .items(). However, mget is a backend-internal method — the public API is config.SOME_KEY and the get_values() / get_values_for_keys() utility functions, none of which are affected. Potential custom Backend subclasses that override mget will need to be updated to return a dict. 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.

    Diff: 408 lines (+306 / -102) across 5 files Reviewer: Mogost Review duration: 9036m
    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
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 44.8% (MEDIUM) · Higher = larger blast radius
    44.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.7% · Safe to merge
    17.7%