diff options
| author | Nasir Hussain <nasirhjafri@gmail.com> | 2019-01-15 01:52:09 +0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2019-01-15 07:22:59 -0500 |
| commit | f021c110d02fd7ca32ae56f511b46e5d138b6c73 (patch) | |
| tree | d97f6cc8cfab98191fbe63752edb93a583720b5c /tests | |
| parent | 87bf35abd3df1015d0c08a9251739d6c8454ab32 (diff) | |
Fixed #30099 -- Fixed invalid SQL when filtering a Subquery by an aggregate.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/expressions/tests.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py index ee3676e64a..df92dba432 100644 --- a/tests/expressions/tests.py +++ b/tests/expressions/tests.py @@ -534,6 +534,18 @@ class BasicExpressionsTests(TestCase): outer = Company.objects.filter(pk__in=Subquery(inner.values('pk'))) self.assertFalse(outer.exists()) + def test_subquery_filter_by_aggregate(self): + Number.objects.create(integer=1000, float=1.2) + Employee.objects.create(salary=1000) + qs = Number.objects.annotate( + min_valuable_count=Subquery( + Employee.objects.filter( + salary=OuterRef('integer'), + ).annotate(cnt=Count('salary')).filter(cnt__gt=0).values('cnt')[:1] + ), + ) + self.assertEqual(qs.get().float, 1.2) + def test_explicit_output_field(self): class FuncA(Func): output_field = models.CharField() |
