diff options
| author | Tomáš Ehrlich <tomas.ehrlich@gmail.com> | 2018-03-01 08:55:05 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-03-01 10:51:54 -0500 |
| commit | 3cdc88ba5305f8653fdd1afa36ba9d4d83c426bf (patch) | |
| tree | 2f1042767a53d9e7d16ad0d2013e429fcd87f602 /tests | |
| parent | 2126e9317e80a7d4c42e033dd33d7e3378fdfcf8 (diff) | |
[2.0.x] Fixed #29172 -- Fixed crash with Window expression in a subquery.
Backport of fa352626c2a80bcdcd0fc6492b5fd5130490f05e from master
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/expressions_window/tests.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/expressions_window/tests.py b/tests/expressions_window/tests.py index e61516b4b6..7ade53f429 100644 --- a/tests/expressions_window/tests.py +++ b/tests/expressions_window/tests.py @@ -650,6 +650,19 @@ class WindowFunctionTests(TestCase): salary=Window(expression=Sum(Value(10000), order_by=F('pk').asc())), ) + def test_window_expression_within_subquery(self): + subquery_qs = Employee.objects.annotate( + highest=Window(FirstValue('id'), partition_by=F('department'), order_by=F('salary').desc()) + ).values('highest') + highest_salary = Employee.objects.filter(pk__in=subquery_qs) + self.assertSequenceEqual(highest_salary.values('department', 'salary'), [ + {'department': 'Accounting', 'salary': 50000}, + {'department': 'Sales', 'salary': 55000}, + {'department': 'Marketing', 'salary': 40000}, + {'department': 'IT', 'salary': 60000}, + {'department': 'Management', 'salary': 100000} + ]) + def test_invalid_start_value_range(self): msg = "start argument must be a negative integer, zero, or None, but got '3'." with self.assertRaisesMessage(ValueError, msg): |
