In/Range lookups on annotations consume iterator rhs (regression in 6.1)
Passing an iterator to __in silently produces an empty result on Django 6.1. Regression in 7b54ddd5e6 (refs #36025). FieldGetDbPrepValueIterableMixin.get_prep_lookup() now iterates self.rhs twice: the any() call exhausts it, the second iteration sees nothing, and the lookup compiles to an empty IN ().
On 6.0 the method made a single pass, and the __in docs say "in a given iterable". One possible fix is to materialize the rhs before the any() check.
Change History
(4)
| Triage Stage: |
Unreviewed → Accepted
|
| Owner: |
set to Yassin Bahri
|
| Status: |
new → assigned
|
| Summary: |
In/Range lookups silently return no results when rhs is an iterator (regression in 6.1) → In/Range lookups on annotations consume iterator rhs (regression in 6.1)
|
I reproduced this on current
main, although the issue is narrower than the current description suggests.Iterator right-hand sides for ordinary field lookups already work because
Query.build_filter()materializes them:The regression occurs when the left-hand side resolves to an annotation or alias:
In this path, the iterator reaches
FieldGetDbPrepValueIterableMixin.get_prep_lookup()directly. Theany()expression consumes it, leaving no values for the following iteration.I confirmed the regression boundary:
7b54ddd5e6.7b54ddd5e6.inreturns an empty result, whilerangeraisesValueError.The ticket is valid and actionable. I suggest narrowing the summary to: