mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #30099 -- Fixed invalid SQL when filtering a Subquery by an aggregate.
This commit is contained in:
parent
87bf35abd3
commit
f021c110d0
3 changed files with 14 additions and 0 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue