From b989d213363e0c34ac34ad819a725c7ceb6bbc0b Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Tue, 26 Jan 2021 10:59:05 +0100 Subject: [PATCH] Refs #26602 -- Added tests for aggregating over a RawSQL() annotation. Fixed in 3f32154f40a855afa063095e3d091ce6be21f2c5. Thanks Manav Agarwal for initial test. --- tests/expressions/tests.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py index 463150f8a1..08ea0a51d3 100644 --- a/tests/expressions/tests.py +++ b/tests/expressions/tests.py @@ -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()