fix: respect transform output type for __in lookups (e.g. __year__in)#3420
Open
mvanhorn wants to merge 1 commit into
Open
fix: respect transform output type for __in lookups (e.g. __year__in)#3420mvanhorn wants to merge 1 commit into
mvanhorn wants to merge 1 commit into
Conversation
ngnpope
reviewed
Jun 8, 2026
Member
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I have made things!
Model.objects.filter(start_date__year__in=...)(and other transform-plus-__inlookups) now expects the transform's output element type instead of the base field's type, sostart_date__year__in=list[int]type-checks and alist[str]is correctly flagged.Related issues
Fixes #3411
AI Policy
Description
DjangoContext.resolve_lookup_expected_typewrapped the base field's exact type inIterablefor theInbranch, ignoring any preceding transform (regression in 6.0.5, confirmed by @sobolevn and @ngnpope on 2026-06-02). Forstart_date__year__init expectedIterable[str | date]instead ofIterable[int]. The fix uses the transform's output type for the__inelement type when a transform precedes the lookup, leaving plain lookups unchanged. Atest_filter.ymlcase covers the validlist[int]and invalidlist[str]shapes; the fulltest_filter.ymlsuite passes (18 passed, 0 failed).