[Django] #28293: QuerySet.union(QuerySet.none()) results in an empty queryset, should be the original queryset

10 views
Skip to first unread message

Django

unread,
Jun 9, 2017, 4:33:45 PM6/9/17
to django-...@googlegroups.com
#28293: QuerySet.union(QuerySet.none()) results in an empty queryset, should be the
original queryset
-------------------------------------+-------------------------------------
Reporter: Jon | Owner: nobody
Dufresne |
Type: Bug | Status: new
Component: Database | Version: 1.11
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Tested on Django 1.11.2.

As `QuerySet.union()` uses the SQL `UNION` operator, I would expect "SET1
UNION <EMPTY SET>" to result in SET1. Currently it results in the empty
set.

{{{
>>> from django.contrib.auth.models import User
>>> User.objects.count()
100
>>> list(User.objects.all().union(User.objects.none()))
[]
}}}

From https://www.postgresql.org/docs/current/static/queries-union.html

> UNION effectively appends the result of query2 to the result of query1
...

`QuerySet.difference()` looks to suffer from the same issue.

--
Ticket URL: <https://code.djangoproject.com/ticket/28293>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 9, 2017, 7:09:45 PM6/9/17
to django-...@googlegroups.com
#28293: QuerySet.union(QuerySet.none()) results in an empty queryset, should be the
original queryset
-------------------------------------+-------------------------------------
Reporter: Jon Dufresne | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


Comment:

Marking as ''Release blocker'' since it's a bug in a newly introduced
feature.

--
Ticket URL: <https://code.djangoproject.com/ticket/28293#comment:1>

Django

unread,
Jun 10, 2017, 11:25:17 AM6/10/17
to django-...@googlegroups.com
#28293: QuerySet.union(QuerySet.none()) results in an empty queryset, should be the
original queryset
-------------------------------------+-------------------------------------
Reporter: Jon Dufresne | Owner: felixxm
Type: Bug | Status: assigned

Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* owner: nobody => felixxm
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/28293#comment:2>

Django

unread,
Jun 11, 2017, 8:57:51 AM6/11/17
to django-...@googlegroups.com
#28293: QuerySet.union(QuerySet.none()) results in an empty queryset, should be the
original queryset
-------------------------------------+-------------------------------------
Reporter: Jon Dufresne | Owner: felixxm
Type: Bug | Status: assigned
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/8629 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/28293#comment:3>

Django

unread,
Jun 13, 2017, 2:16:31 AM6/13/17
to django-...@googlegroups.com
#28293: QuerySet.union(QuerySet.none()) results in an empty queryset, should be the
original queryset
-------------------------------------+-------------------------------------
Reporter: Jon Dufresne | Owner: felixxm
Type: Bug | Status: closed

Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"82175ead723f8fa3f9271fbd4b24275097029aab" 82175ead]:
{{{
#!CommitTicketReference repository=""
revision="82175ead723f8fa3f9271fbd4b24275097029aab"
Fixed #28293 -- Fixed union(), intersection(), and difference() when
combining with an EmptyQuerySet.

Thanks Jon Dufresne for the report and Tim Graham for the review.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28293#comment:4>

Django

unread,
Jun 13, 2017, 2:36:03 AM6/13/17
to django-...@googlegroups.com
#28293: QuerySet.union(QuerySet.none()) results in an empty queryset, should be the
original queryset
-------------------------------------+-------------------------------------
Reporter: Jon Dufresne | Owner: felixxm
Type: Bug | Status: closed
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"44e29ea1e906859e85bb2a46ae5ea9d82bd96f5f" 44e29ea1]:
{{{
#!CommitTicketReference repository=""
revision="44e29ea1e906859e85bb2a46ae5ea9d82bd96f5f"
[1.11.x] Fixed #28293 -- Fixed union(), intersection(), and difference()


when combining with an EmptyQuerySet.

Thanks Jon Dufresne for the report and Tim Graham for the review.

Backport of 82175ead723f8fa3f9271fbd4b24275097029aab from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28293#comment:5>

Reply all
Reply to author
Forward
0 new messages