Skip to content

fix: respect transform output type for __in lookups (e.g. __year__in)#3420

Open
mvanhorn wants to merge 1 commit into
typeddjango:masterfrom
mvanhorn:fix/3411-year-in-transform-lookup-regression
Open

fix: respect transform output type for __in lookups (e.g. __year__in)#3420
mvanhorn wants to merge 1 commit into
typeddjango:masterfrom
mvanhorn:fix/3411-year-in-transform-lookup-regression

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Jun 8, 2026

Copy link
Copy Markdown

I have made things!

Model.objects.filter(start_date__year__in=...) (and other transform-plus-__in lookups) now expects the transform's output element type instead of the base field's type, so start_date__year__in=list[int] type-checks and a list[str] is correctly flagged.

Related issues

Fixes #3411

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

Description

DjangoContext.resolve_lookup_expected_type wrapped the base field's exact type in Iterable for the In branch, ignoring any preceding transform (regression in 6.0.5, confirmed by @sobolevn and @ngnpope on 2026-06-02). For start_date__year__in it expected Iterable[str | date] instead of Iterable[int]. The fix uses the transform's output type for the __in element type when a transform precedes the lookup, leaving plain lookups unchanged. A test_filter.yml case covers the valid list[int] and invalid list[str] shapes; the full test_filter.yml suite passes (18 passed, 0 failed).

@ngnpope ngnpope 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.

Three quick comments:

  • Can you extract this transform type lookup to a helper function? I'm sure this will be needed in more places.
  • Can you check if anything needs to be done when filtering on an annotated field?
  • More tests should be added for other transforms, not just year.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

__year__in (transform + __in) regressed in 6.0.5: rejects list[int], expects Iterable[str | date]

2 participants