← Back to Pull requests

Type file fields as their stored name in `values()` and `values_list()` #3876

Merged
UnknownPlatypus merged 7 files (180 lines) on Dec 03, 2026 12:58 UTC
View on GitHub
UnknownPlatypus UnknownPlatypus commented on Dec 02, 2026 16:20 UTC
Author

I have made things!

FileField used FieldFile as its get type, but that's only what attribute access gives (see FileDescriptor.__get__), values(), values_list() and aggregates return the stored name.

  • The get type is now str (str | None with null=True, same __init__ overloads as the other fields) and __get__ returns FieldFile / ImageFieldFile directly.

  • The plugin reads the get type for values() instead of __get__, so I could drop the file field special case in the null=True widening.
  • Followup to #3763

    AI Policy


  • I have read and agree to the AI Policy, removed any "Co-Authored-By" lines attributing coding agents, and manually reviewed the final result
  • Diff: 180 lines (+158 / -22) across 7 files Reviewer: sobolevn Review duration: 1238m
    All Vouch review confidence checks passed
    Residual risk 0.04 = Change Risk (0.43) × (1 − Review Confidence (0.92)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 180 lines diff across 7 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.92 · 3 substantive comment(s)
    0.92
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    91%
    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.311
    Real PR Conversation Timeline
    4 items
    sobolevn sobolevn commented on code on Dec 02, 2026 19:05 UTC
    Code Review
    tests/assert_type/db/models/test_queryset_row_type/models.py:1
    @@ -62,3 +63,27 @@ async def async_queryset_methods_keep_the_row_type(qs: QuerySet[Blog], manager:
         assert_type(manager.aiterator(), AsyncIterator[Blog])
         async for blog in qs:
             assert_type(blog, Blog)
    +
    +
    +class PathFileField(models.FileField[Any, Path]):
    +    def from_db_value(self, value: str, expression: object, connection: object) -> Path:
    +        return Path(value)
    +
    +
    +class Upload(models.Model):
    +    logo = models.ImageField()
    +    doc = models.FileField(null=True)
    +    path = PathFileField()
    +
    +
    +def values_read_the_stored_file_name() -> None:
    +    # only the mypy plugin types `values()` and `values_list()` columns, the stubs return `Any`

    should this be in .yml test file?

    UnknownPlatypus UnknownPlatypus commented on code on Dec 03, 2026 00:48 UTC
    Code Review
    tests/assert_type/db/models/test_queryset_row_type/models.py:1
    @@ -62,3 +63,27 @@ async def async_queryset_methods_keep_the_row_type(qs: QuerySet[Blog], manager:
         assert_type(manager.aiterator(), AsyncIterator[Blog])
         async for blog in qs:
             assert_type(blog, Blog)
    +
    +
    +class PathFileField(models.FileField[Any, Path]):
    +    def from_db_value(self, value: str, expression: object, connection: object) -> Path:
    +        return Path(value)
    +
    +
    +class Upload(models.Model):
    +    logo = models.ImageField()
    +    doc = models.FileField(null=True)
    +    path = PathFileField()
    +
    +
    +def values_read_the_stored_file_name() -> None:
    +    # only the mypy plugin types `values()` and `values_list()` columns, the stubs return `Any`

    I prefer everything in python files so we track possible plugin code progress on other typecheckers.

    I would just like for it to be easier to understand when ignores are expected or false positives. Currently it's not ideal.

    Basically no ignores or all 4 ignores are usually correct behavior, anything in between is probably a bug on at least one checker. But this is not super visible currently. Probably something we would want easier if we find a better solution for #3343

    sobolevn sobolevn commented on code on Dec 03, 2026 09:28 UTC
    Code Review
    tests/assert_type/db/models/test_queryset_row_type/models.py:1
    @@ -62,3 +63,27 @@ async def async_queryset_methods_keep_the_row_type(qs: QuerySet[Blog], manager:
         assert_type(manager.aiterator(), AsyncIterator[Blog])
         async for blog in qs:
             assert_type(blog, Blog)
    +
    +
    +class PathFileField(models.FileField[Any, Path]):
    +    def from_db_value(self, value: str, expression: object, connection: object) -> Path:
    +        return Path(value)
    +
    +
    +class Upload(models.Model):
    +    logo = models.ImageField()
    +    doc = models.FileField(null=True)
    +    path = PathFileField()
    +
    +
    +def values_read_the_stored_file_name() -> None:
    +    # only the mypy plugin types `values()` and `values_list()` columns, the stubs return `Any`

    then - lgtm

    Reviewers
    Assignees
    UnknownPlatypus UnknownPlatypus
    Labels
    risk: low confidence: 91.8% 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: 42.9% (MEDIUM) · Higher = larger blast radius
    42.9%
    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: 91.8% · Lower = rushed or shallow review
    91.8%
    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: 3.5% · Safe to merge
    3.5%