mirror of
https://github.com/django/django.git
synced 2025-06-07 12:39:12 +00:00
Fixed #36388 -- Made QuerySet.union() return self when called with no arguments.
Regression in 9cb8baa0c4fa2c10789c5c8b65f4465932d4d172. Thank you to Antoine Humeau for the report and Simon Charette for the review.
This commit is contained in:
parent
1ba5fe19ca
commit
802baf5da5
1
AUTHORS
1
AUTHORS
@ -239,6 +239,7 @@ answer newbie questions, and generally made Django that much better:
|
|||||||
Claude Paroz <claude@2xlibre.net>
|
Claude Paroz <claude@2xlibre.net>
|
||||||
Clifford Gama <cliffygamy@gmail.com>
|
Clifford Gama <cliffygamy@gmail.com>
|
||||||
Clint Ecker
|
Clint Ecker
|
||||||
|
Colleen Dunlap <https://medium.com/@colleen85052>
|
||||||
colin@owlfish.com
|
colin@owlfish.com
|
||||||
Colin Wood <cwood06@gmail.com>
|
Colin Wood <cwood06@gmail.com>
|
||||||
Collin Anderson <cmawebsite@gmail.com>
|
Collin Anderson <cmawebsite@gmail.com>
|
||||||
|
@ -1550,6 +1550,8 @@ class QuerySet(AltersData):
|
|||||||
if len(qs) == 1:
|
if len(qs) == 1:
|
||||||
return qs[0]
|
return qs[0]
|
||||||
return qs[0]._combinator_query("union", *qs[1:], all=all)
|
return qs[0]._combinator_query("union", *qs[1:], all=all)
|
||||||
|
elif not other_qs:
|
||||||
|
return self
|
||||||
return self._combinator_query("union", *other_qs, all=all)
|
return self._combinator_query("union", *other_qs, all=all)
|
||||||
|
|
||||||
def intersection(self, *other_qs):
|
def intersection(self, *other_qs):
|
||||||
|
@ -15,3 +15,6 @@ Bugfixes
|
|||||||
* Fixed a bug in Django 5.2 where subqueries using ``"pk"`` to reference models
|
* Fixed a bug in Django 5.2 where subqueries using ``"pk"`` to reference models
|
||||||
with a ``CompositePrimaryKey`` failed to raise ``ValueError`` when too many
|
with a ``CompositePrimaryKey`` failed to raise ``ValueError`` when too many
|
||||||
or too few columns were selected (:ticket:`36392`).
|
or too few columns were selected (:ticket:`36392`).
|
||||||
|
|
||||||
|
* Fixed a regression in Django 5.2 that caused a crash when no arguments were
|
||||||
|
passed into ``QuerySet.union()`` (:ticket:`36388`).
|
||||||
|
@ -88,6 +88,13 @@ class QuerySetSetOperationTests(TestCase):
|
|||||||
qs3 = qs1.union(qs2)
|
qs3 = qs1.union(qs2)
|
||||||
self.assertNumbersEqual(qs3[:1], [0])
|
self.assertNumbersEqual(qs3[:1], [0])
|
||||||
|
|
||||||
|
def test_union_empty_slice(self):
|
||||||
|
qs = Number.objects.union()
|
||||||
|
self.assertNumbersEqual(qs[:1], [0])
|
||||||
|
qs = Number.objects.union(all=True)
|
||||||
|
self.assertNumbersEqual(qs[:1], [0])
|
||||||
|
self.assertNumbersEqual(qs.order_by("num")[0:], list(range(0, 10)))
|
||||||
|
|
||||||
def test_union_all_none_slice(self):
|
def test_union_all_none_slice(self):
|
||||||
qs = Number.objects.filter(id__in=[])
|
qs = Number.objects.filter(id__in=[])
|
||||||
with self.assertNumQueries(0):
|
with self.assertNumQueries(0):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user