Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#2038 closed defect (fixed)

QuerySet._combine does not combine where clause

Reported by: graham@… Owned by: Adrian Holovaty
Component: contrib.admin Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In db/models/query.py, QuerySet, the _combine method does not actually combine the two query sets. Instead if clones the second one and returns that.

To reproduce:

  • Create a custom manager for an object that uses the admin interface, and has a search box.
  • Make that custom manager change the 'where' clause of it's query set, for example by using the 'extra' method to limit the query via a join.
  • List the objects in the admin interface. You will see the limited set, which is correct.
  • Use the search box on the list admin page. The results now returned are not limited by your manager, because the 'where' clause gets lost.

Change History (2)

comment:1 by graham@…, 19 years ago

Adding this in QuerySet._combine from line 384 fixes it:

        if self._select: combined._select.update(self._select)
        if self._where: combined._where.extend(self._where)
        if self._params: combined._params.extend(self._params)
        if self._tables: combined._tables.extend(self._tables) 

I can provide a patch if needed.

comment:2 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: newclosed

(In [3019]) Fixed #2038 -- QuerySet._combine now combines where clause. Thanks, graham@…

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