Refs #26602 -- Added tests for aggregating over a RawSQL() annotation.

Fixed in 3f32154f40.

Thanks Manav Agarwal for initial test.
This commit is contained in:
Mariusz Felisiak 2021-01-26 10:59:05 +01:00 committed by GitHub
parent 1adc09064f
commit b989d21336
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 0 deletions

View File

@ -670,6 +670,18 @@ class BasicExpressionsTests(TestCase):
# contain nested aggregates.
self.assertNotIn('GROUP BY', sql)
@skipUnlessDBFeature('supports_over_clause')
def test_aggregate_rawsql_annotation(self):
with self.assertNumQueries(1) as ctx:
aggregate = Company.objects.annotate(
salary=RawSQL('SUM(num_chairs) OVER (ORDER BY num_employees)', []),
).aggregate(
count=Count('pk'),
)
self.assertEqual(aggregate, {'count': 3})
sql = ctx.captured_queries[0]['sql']
self.assertNotIn('GROUP BY', sql)
def test_explicit_output_field(self):
class FuncA(Func):
output_field = CharField()