mirror of https://github.com/django/django.git
[2.0.x] Fixed #28689 -- Fixed unquoted table names in Subquery SQL when using OuterRef.
Regression inf48bc7c3db
. Backport of81e357a7e1
from master
This commit is contained in:
parent
01987bc0b4
commit
f5184ae5dc
|
@ -997,7 +997,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
|
||||
|
|
|
@ -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`).
|
||||
|
|
|
@ -50,6 +50,7 @@ class Experiment(models.Model):
|
|||
end = models.DateTimeField()
|
||||
|
||||
class Meta:
|
||||
db_table = 'expressions_ExPeRiMeNt'
|
||||
ordering = ('name',)
|
||||
|
||||
def duration(self):
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue