Opened 7 years ago

Last modified 7 years ago

#28378 closed Bug

QuerySet.union() with queryset that raises EmptyResultSet results in an empty set — at Version 4

Reported by: Jon Dufresne Owned by: nobody
Component: Database layer (models, ORM) Version: 1.11
Severity: Release blocker Keywords:
Cc: Mariusz Felisiak 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))
[]

Change History (5)

comment:1 by Mariusz Felisiak, 7 years ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

comment:2 by Mariusz Felisiak, 7 years ago

difference is also affected.

by Mariusz Felisiak, 7 years ago

Attachment: 28378.diff added

comment:3 by Mariusz Felisiak, 7 years ago

Cc: Mariusz Felisiak added

I attached tests.

comment:4 by Sergey Fedoseev, 7 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top