Opened 9 years ago

Closed 8 years ago

Last modified 5 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:

Description

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
source:/django/branches/newforms-admin/django/contrib/admin/views/main.py#7544#L306

Attachments (1)

test.py (1.6 KB) - added by Erik Stein 9 years ago.

Download all attachments as: .zip

Change History (7)

Changed 9 years ago by Erik Stein

Attachment: test.py added

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

Keywords: nfa-someday added

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

comment:2 Changed 9 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 8 years ago by Jacob

milestone: 1.0

comment:4 Changed 8 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 8 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 5 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

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