Opened 13 months ago

Closed 13 months ago

Last modified 13 months ago

#28378 closed Bug (fixed)

QuerySet.union() with queryset that raises EmptyResultSet results in an empty set

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

Description (last modified by Sergey Fedoseev)

Similar and followup to ticket #28293. Tested on Django 1.11.3.

As QuerySet.union() uses the SQL UNION operator, I would expect "SET1 UNION <EMPTY SET>" to result in SET1. If the empty set is the results of EmpytResultSet being raised, the .union() result is an empty set, not SET1.

Example test case:

>>> import django
>>> django.__version__
'1.11.3'
>>> from django.contrib.auth.models import User
>>> qs1 = User.objects.all() 
>>> qs1.count()
100
>>> qs2 = User.objects.filter(pk__in=[])
>>> qs2.count()
0
>>> list(qs1.union(qs2))
[]

Attachments (1)

28378.diff (1.7 KB) - added by felixxm 13 months ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 13 months ago by felixxm

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

comment:2 Changed 13 months ago by felixxm

difference is also affected.

Changed 13 months ago by felixxm

Attachment: 28378.diff added

comment:3 Changed 13 months ago by felixxm

Cc: felixxm added

I attached tests.

comment:4 Changed 13 months ago by Sergey Fedoseev

Description: modified (diff)

comment:5 Changed 13 months ago by felixxm

Owner: changed from nobody to felixxm
Status: newassigned

comment:6 Changed 13 months ago by felixxm

Has patch: set

comment:7 Changed 13 months ago by Simon Charette

Triage Stage: AcceptedReady for checkin

Patch LGTM, it's only missing release notes.

comment:8 Changed 13 months ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In ca74e563:

Fixed #28378 -- Fixed union() and difference() when combining with a queryset raising EmptyResultSet.

Thanks Jon Dufresne for the report. Thanks Tim Graham and Simon Charette
for the reviews.

comment:9 Changed 13 months ago by Mariusz Felisiak <felisiak.mariusz@…>

In 346b46a:

[1.11.x] Fixed #28378 -- Fixed union() and difference() when combining with a queryset raising EmptyResultSet.

Thanks Jon Dufresne for the report. Thanks Tim Graham and Simon Charette
for the reviews.

Backport of ca74e563500e291480f1976b58fcd34aac768dca from master

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