Opened 16 years ago

Closed 16 years ago

Last modified 12 years ago

#7314 closed (fixed)

Combining querysets remove extra-Subquery

Reported by: Erik Stein Owned by: nobody
Component: Uncategorized Version: dev
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: no UI/UX: no

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 16 years ago.

Download all attachments as: .zip

Change History (7)

by Erik Stein, 16 years ago

Attachment: test.py added

comment:1 by Karen Tracey <kmtracey@…>, 16 years ago

Keywords: nfa-someday added

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

comment:2 by George Vilches, 16 years ago

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 by Jacob, 16 years ago

milestone: 1.0

comment:4 by Malcolm Tredinnick, 16 years ago

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 by Malcolm Tredinnick, 16 years ago

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 by Jacob, 12 years ago

milestone: 1.0

Milestone 1.0 deleted

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