Opened 10 years ago

Closed 8 years ago

#2253 closed defect (fixed)

Combining QuerySets via | operator does not always work

Reported by: jeffrey.a.zelt@… Owned by: anonymous
Component: Database layer (models, ORM) Version: master
Severity: major Keywords: qs-rf-fixed
Cc: mir@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: UI/UX:

Description

I am working through the first example model in the documentation (http://www.djangoproject.com/documentation/models/basic/). Using that model as a reference, I can show the output here from the python interpeter that where the "|" operator generates an incorrect result (but the "&" operator seems to work OK):

all = Article.objects.all()
one = Article.objects.filter(id=1)

all

[<Article: Area womman programs in Python>, <Article: Second article>, <Article: Third article>, <Article: Fourth article>, <Article: Article 6>, <Article: Default headline>, <Article: Article 7>, <Article: Article 8>, <Article: Article 9>, <Article: Article 7>]

one

[<Article: Area womman programs in Python>]

all | one

[<Article: Area womman programs in Python>] <-- should be the union of the two QuerySets, but it is not

all & one

[<Article: Area womman programs in Python>]

The operation: "all | one" should have been the union of these two ResultSets, but here it is a list containing only a single object. Note that the intersection "all & one" is, however, correct. Here are a few more details:

import django
django.VERSION

(0, 95, 'post-magic-removal')

Specifically, this is for revision 3214.

Change History (9)

comment:1 Changed 10 years ago by mir@…

Cc: mir@… added

comment:2 Changed 10 years ago by Chris Beaven

Needs tests: set
Triage Stage: UnreviewedAccepted

mir, care to write up a test (if not the whole patch ;))

comment:3 Changed 9 years ago by Adrian Holovaty

Version: magic-removalSVN

comment:4 Changed 9 years ago by Malcolm Tredinnick

Keywords: qs-rf-fixed added

comment:5 Changed 9 years ago by ionut bizau

Owner: changed from nobody to ionut bizau
Status: newassigned

comment:6 Changed 9 years ago by ionut bizau

Owner: ionut bizau deleted
Status: assignednew

comment:7 Changed 9 years ago by anonymous

Owner: set to anonymoulfjkfs

comment:8 Changed 9 years ago by Chris Beaven

Owner: changed from anonymoulfjkfs to anonymous

comment:9 Changed 8 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(In [7477]) Merged the queryset-refactor branch into trunk.

This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.

Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658

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