mirror of
https://github.com/django/django.git
synced 2025-10-25 22:56:12 +00:00
[5.2.x] Fixed #36025 -- Fixed re-aliasing of iterable (in/range) lookups rhs.
In order for Expression.relabeled_clone to work appropriately its
get_source_expressions method must return all resolvable which wasn't the case
for Lookup when its right-hand-side is "direct" (not a compilable).
While refs #22288 added support for non-literals iterable right-hand-side
lookups it predated the subclassing of Lookup(Expression) refs #27021 which
could have been an opportunity to ensure right-hand-sides are always resolvable
(ValueList and ExpressionList).
Addressing all edge case with non-resolvable right-hand-sides would require
a significant refactor and deprecation of some parts of the Lookup interface so
this patch only focuses on FieldGetDbPrepValueIterableMixin (In and Range
lookups) by making sure that a right-hand-side containing resolvables are dealt
with appropriately during the resolving phase.
Thanks Aashay Amballi for the report.
Backport of 089deb82b9 from main.
This commit is contained in:
committed by
Sarah Boyce
parent
b96e4c04b6
commit
d99985bbc1
@@ -1276,6 +1276,23 @@ class IterableLookupInnerExpressionsTests(TestCase):
|
||||
queryset = Result.objects.filter(**{lookup: within_experiment_time})
|
||||
self.assertSequenceEqual(queryset, [r1])
|
||||
|
||||
def test_relabeled_clone_rhs(self):
|
||||
Number.objects.bulk_create([Number(integer=1), Number(integer=2)])
|
||||
self.assertIs(
|
||||
Number.objects.filter(
|
||||
# Ensure iterable of expressions are properly re-labelled on
|
||||
# subquery pushdown. If the inner query __range right-hand-side
|
||||
# members are not relabelled they will point at the outer query
|
||||
# alias and this test will fail.
|
||||
Exists(
|
||||
Number.objects.exclude(pk=OuterRef("pk")).filter(
|
||||
integer__range=(F("integer"), F("integer"))
|
||||
)
|
||||
)
|
||||
).exists(),
|
||||
True,
|
||||
)
|
||||
|
||||
|
||||
class FTests(SimpleTestCase):
|
||||
def test_deepcopy(self):
|
||||
|
||||
Reference in New Issue
Block a user