Opened 3 years ago

Closed 3 years ago

Last modified 3 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 Changed 3 years ago by Simon Charette

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

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

comment:2 Changed 3 years ago by Mariusz Felisiak

Owner: changed from nobody to Mariusz Felisiak
Status: newassigned

comment:3 Changed 3 years ago by Mariusz Felisiak

Has patch: set

comment:4 Changed 3 years ago by GitHub <noreply@…>

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 Changed 3 years ago by Mariusz Felisiak <felisiak.mariusz@…>

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