Opened 10 years ago

Closed 10 years ago

Last modified 7 years ago

#7314 closed (fixed)

Combining querysets remove extra-Subquery

Reported by: Erik Stein Owned by: nobody
Component: Uncategorized Version: master
Severity: Keywords: qsrf-cleanup nfa-someday
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


If I combine two queries where the first one has an extra where clause defining a subquery, the subquery is removed from the resulting queryset. The queryset gives wrong results.

See attached test.

The method to combine queries this way is used in ChangeList.get_query_set, see

Attachments (1) (1.6 KB) - added by Erik Stein 10 years ago.

Download all attachments as: .zip

Change History (7)

Changed 10 years ago by Erik Stein

Attachment: added

comment:1 Changed 10 years ago by Karen Tracey <kmtracey@…>

Keywords: nfa-someday added

Code is same on trunk as nfa, should not block merge.

comment:2 Changed 10 years ago by George Vilches

Keywords: qsrf-cleanup added

This looks to me more like a straight QuerySet problem, unrelated to NFA. Am I wrong? Tagging with qsrf-cleanup for now.

comment:3 Changed 10 years ago by Jacob

milestone: 1.0

comment:4 Changed 10 years ago by Malcolm Tredinnick

Triage Stage: UnreviewedAccepted
Version: newforms-adminSVN

The line of code pointed to in the description doesn't use extra() at all. Still, this is a semi-bug: we use only the extra bits from the RHS. I'll merge them together, but people shouldn't expect miracles when it comes to this always working, since Django isn't going to rewrite aliases in extra() for you (that would require writing an SQL parser).

comment:5 Changed 10 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(In [7791]) Fixed #7314 -- Changed the way extra() bits are handled when QuerySets are merged.

Also added a section to the documentation to indicate why it's probably not a
good idea to rely on this feature for complex stuff. Garbage in, garbage out
applies even to Django code.

Thanks to erik for the test case for this one.

comment:6 Changed 7 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

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