Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#28293 closed Bug (fixed)

QuerySet.union(QuerySet.none()) results in an empty queryset, should be the original queryset

Reported by: Jon Dufresne Owned by: Mariusz Felisiak
Component: Database layer (models, ORM) Version: 1.11
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (5)

comment:1 by Simon Charette, 7 years ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

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

comment:2 by Mariusz Felisiak, 7 years ago

Owner: changed from nobody to Mariusz Felisiak
Status: newassigned

comment:3 by Mariusz Felisiak, 7 years ago

Has patch: set

comment:4 by GitHub <noreply@…>, 7 years ago

Resolution: fixed
Status: assignedclosed

In 82175ead:

Fixed #28293 -- Fixed union(), intersection(), and difference() when combining with an EmptyQuerySet.

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

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 7 years ago

In 44e29ea1:

[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

Note: See TracTickets for help on using tickets.
Back to Top