diff options
author | Francesco Panico <panico.francesco@gmail.com> | 2023-01-18 22:42:53 +0000 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-01-20 08:51:38 +0100 |
commit | cc8aa6bf9c127a493e6dd005012b9e6397b3f319 (patch) | |
tree | 39ad5135128ef96d627bbdaf2d7a9bc1bd8120b0 /tests/queries | |
parent | 79c298c9ceb8e386f172330236f04bb0ae4f7fdd (diff) | |
download | django-cc8aa6bf9c127a493e6dd005012b9e6397b3f319.tar.gz |
Fixed #34267 -- Fixed sliced QuerySet.union() crash.
Regression in 3d734c09ff0138441dfe0a59010435871d17950f.
Thanks Raphaƫl Stefanini for the report.
Diffstat (limited to 'tests/queries')
-rw-r--r-- | tests/queries/test_qs_combinators.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/tests/queries/test_qs_combinators.py b/tests/queries/test_qs_combinators.py index 6358e537ae..96a5b24cc1 100644 --- a/tests/queries/test_qs_combinators.py +++ b/tests/queries/test_qs_combinators.py @@ -87,6 +87,15 @@ class QuerySetSetOperationTests(TestCase): qs3 = qs1.union(qs2) self.assertNumbersEqual(qs3.order_by("num")[2:3], [2]) + def test_union_slice_index(self): + Celebrity.objects.create(name="Famous") + c1 = Celebrity.objects.create(name="Very famous") + + qs1 = Celebrity.objects.filter(name="nonexistent") + qs2 = Celebrity.objects.all() + combined_qs = qs1.union(qs2).order_by("name") + self.assertEqual(combined_qs[1], c1) + def test_union_order_with_null_first_last(self): Number.objects.filter(other_num=5).update(other_num=None) qs1 = Number.objects.filter(num__lte=1) @@ -319,10 +328,10 @@ class QuerySetSetOperationTests(TestCase): e1 = ExtraInfo.objects.create(value=7, info="e1") a1 = Author.objects.create(name="a1", num=1, extra=e1) Author.objects.create(name="a2", num=3, extra=e1) - base_qs = Author.objects.select_related("extra") + base_qs = Author.objects.select_related("extra").order_by() qs1 = base_qs.filter(name="a1") qs2 = base_qs.filter(name="a2") - self.assertEqual(qs1.union(qs2).first(), a1) + self.assertEqual(qs1.union(qs2).order_by("name").first(), a1) def test_union_with_first(self): e1 = ExtraInfo.objects.create(value=7, info="e1") @@ -455,8 +464,7 @@ class QuerySetSetOperationTests(TestCase): captured_sql, ) self.assertEqual( - captured_sql.count(connection.ops.limit_offset_sql(None, 1)), - 3 if connection.features.supports_slicing_ordering_in_compound else 1, + captured_sql.count(connection.ops.limit_offset_sql(None, 1)), 1 ) def test_exists_union_empty_result(self): |