Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#2038 closed defect (fixed)

QuerySet._combine does not combine where clause

Reported by: graham@… Owned by: adrian
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: UI/UX:

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 Changed 9 years ago by graham@…

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 Changed 9 years ago by adrian

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

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

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