Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#7314 closed (fixed)

Combining querysets remove extra-Subquery

Reported by: erik 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 8 years ago.

Download all attachments as: .zip

Change History (7)

Changed 8 years ago by erik

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

  • Keywords nfa-someday added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 8 years ago by gav

  • 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 8 years ago by jacob

  • milestone set to 1.0

comment:4 Changed 8 years ago by mtredinnick

  • Triage Stage changed from Unreviewed to Accepted
  • Version changed from newforms-admin to SVN

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 8 years ago by mtredinnick

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

(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 5 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

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