Django

Code

Ticket #7314 (closed: fixed)

Opened 3 months ago

Last modified 2 months ago

Combining querysets remove extra-Subquery

Reported by: erik Assigned to: nobody
Milestone: 1.0 Component: Uncategorized
Version: SVN Keywords: qsrf-cleanup nfa-someday
Cc: Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

test.py (1.6 kB) - added by erik on 05/27/08 15:18:59.

Change History

05/27/08 15:18:59 changed by erik

  • attachment test.py added.

06/09/08 18:15:50 changed by Karen Tracey <kmtracey@gmail.com>

  • keywords set to nfa-someday.
  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

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

06/10/08 09:39:06 changed by gav

  • keywords changed from nfa-someday to qsrf-cleanup nfa-someday.

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

06/16/08 12:10:45 changed by jacob

  • milestone set to 1.0.

06/30/08 00:32:28 changed by mtredinnick

  • version changed from newforms-admin to SVN.
  • stage changed from Unreviewed to Accepted.

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).

06/30/08 01:24:22 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(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.


Add/Change #7314 (Combining querysets remove extra-Subquery)




Change Properties
Action