Code

Opened 8 years ago

Closed 6 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.

Attachments (0)

Change History (9)

comment:1 Changed 8 years ago by mir@…

  • Cc mir@… added

comment:2 Changed 7 years ago by SmileyChris

  • Needs tests set
  • Triage Stage changed from Unreviewed to Accepted

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

comment:3 Changed 7 years ago by adrian

  • Version changed from magic-removal to SVN

comment:4 Changed 7 years ago by mtredinnick

  • Keywords qs-rf-fixed added

comment:5 Changed 6 years ago by ionut_bizau

  • Owner changed from nobody to ionut_bizau
  • Status changed from new to assigned

comment:6 Changed 6 years ago by ionut_bizau

  • Owner ionut_bizau deleted
  • Status changed from assigned to new

comment:7 Changed 6 years ago by anonymous

  • Owner set to anonymoulfjkfs

comment:8 Changed 6 years ago by SmileyChris

  • Owner changed from anonymoulfjkfs to anonymous

comment:9 Changed 6 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.