浏览代码

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

Fixed in 3f32154f40a855afa063095e3d091ce6be21f2c5.

Thanks Manav Agarwal for initial test.
Mariusz Felisiak 4 年之前
父节点
当前提交
b989d21336
共有 1 个文件被更改,包括 12 次插入0 次删除
  1. 12 0
      tests/expressions/tests.py

+ 12 - 0
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()