1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #27862 -- Fixed incorrectly quoted table aliases in Subquery SQL.

Add aliases from resolved querysets to the parent query's external
aliases to prevent those aliases from being quoted.

Thanks to Vasily Stepanov for the report and Tim Graham for the review.
This commit is contained in:
Matthew Schinckel
2017-02-25 21:11:56 +10:30
committed by Tim Graham
parent 9f21e35100
commit f48bc7c3db
2 changed files with 15 additions and 1 deletions

View File

@@ -516,6 +516,15 @@ class BasicExpressionsTests(TestCase):
[{'salary': 10, 'total_employees': 2300}, {'salary': 20, 'total_employees': 35}],
)
def test_subquery_references_joined_table_twice(self):
inner = Company.objects.filter(
num_chairs__gte=OuterRef('ceo__salary'),
num_employees__gte=OuterRef('point_of_contact__salary'),
)
# Another contrived example (there is no need to have a subquery here)
outer = Company.objects.filter(pk__in=Subquery(inner.values('pk')))
self.assertFalse(outer.exists())
class IterableLookupInnerExpressionsTests(TestCase):
@classmethod