1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Fixed #28689 -- Fixed unquoted table names in Subquery SQL when using OuterRef.

Regression in f48bc7c3db.
This commit is contained in:
Mariusz Felisiak 2017-10-25 21:52:38 +02:00 committed by GitHub
parent 171c7cc863
commit 81e357a7e1
4 changed files with 10 additions and 1 deletions

View File

@ -985,7 +985,7 @@ class Subquery(Expression):
)
# Add table alias to the parent query's aliases to prevent
# quoting.
if hasattr(resolved, 'alias'):
if hasattr(resolved, 'alias') and resolved.alias != resolved.target.model._meta.db_table:
clone.queryset.query.external_aliases.add(resolved.alias)
return resolved
return child

View File

@ -16,3 +16,6 @@ Bugfixes
* Made ``QuerySet.reverse()`` affect ``nulls_first`` and ``nulls_last``
(:ticket:`28722`).
* Fixed unquoted table names in ``Subquery`` SQL when using ``OuterRef``
(:ticket:`28689`).

View File

@ -50,6 +50,7 @@ class Experiment(models.Model):
end = models.DateTimeField()
class Meta:
db_table = 'expressions_ExPeRiMeNt'
ordering = ('name',)
def duration(self):

View File

@ -545,6 +545,11 @@ class BasicExpressionsTests(TestCase):
expr = FuncB(FuncA())
self.assertEqual(expr.output_field, FuncA.output_field)
def test_outerref_mixed_case_table_name(self):
inner = Result.objects.filter(result_time__gte=OuterRef('experiment__assigned'))
outer = Result.objects.filter(pk__in=Subquery(inner.values('pk')))
self.assertFalse(outer.exists())
class IterableLookupInnerExpressionsTests(TestCase):
@classmethod