mirror of
https://github.com/django/django.git
synced 2025-08-19 02:01:29 +00:00
Fixed #36388 -- Made QuerySet.union() return self when called with no arguments.
Some checks failed
Docs / docs (push) Waiting to run
Docs / blacken-docs (push) Waiting to run
Linters / flake8 (push) Has been cancelled
Linters / isort (push) Has been cancelled
Linters / black (push) Has been cancelled
Tests / Windows, SQLite, Python 3.13 (push) Has been cancelled
Tests / JavaScript tests (push) Has been cancelled
Some checks failed
Docs / docs (push) Waiting to run
Docs / blacken-docs (push) Waiting to run
Linters / flake8 (push) Has been cancelled
Linters / isort (push) Has been cancelled
Linters / black (push) Has been cancelled
Tests / Windows, SQLite, Python 3.13 (push) Has been cancelled
Tests / JavaScript tests (push) Has been cancelled
Regression in 9cb8baa0c4
.
Thank you to Antoine Humeau for the report and Simon Charette for the review.
This commit is contained in:
parent
1ba5fe19ca
commit
802baf5da5
4 changed files with 13 additions and 0 deletions
1
AUTHORS
1
AUTHORS
|
@ -239,6 +239,7 @@ answer newbie questions, and generally made Django that much better:
|
|||
Claude Paroz <claude@2xlibre.net>
|
||||
Clifford Gama <cliffygamy@gmail.com>
|
||||
Clint Ecker
|
||||
Colleen Dunlap <https://medium.com/@colleen85052>
|
||||
colin@owlfish.com
|
||||
Colin Wood <cwood06@gmail.com>
|
||||
Collin Anderson <cmawebsite@gmail.com>
|
||||
|
|
|
@ -1550,6 +1550,8 @@ class QuerySet(AltersData):
|
|||
if len(qs) == 1:
|
||||
return qs[0]
|
||||
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)
|
||||
|
||||
def intersection(self, *other_qs):
|
||||
|
|
|
@ -15,3 +15,6 @@ Bugfixes
|
|||
* Fixed a bug in Django 5.2 where subqueries using ``"pk"`` to reference models
|
||||
with a ``CompositePrimaryKey`` failed to raise ``ValueError`` when too many
|
||||
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)
|
||||
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):
|
||||
qs = Number.objects.filter(id__in=[])
|
||||
with self.assertNumQueries(0):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue