Django

Code

Ticket #7312 (closed: fixed)

Opened 6 months ago

Last modified 5 months ago

QuerySet.complex_filter() chokes on custom Q objects (with add_to_query() method)

Reported by: emulbreh Assigned to: nobody
Milestone: 1.0 Component: Database layer (models, ORM)
Version: SVN Keywords: qsrf-cleanup
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

To reproduce, try:

class DoNothingQ:
    def add_to_query(self, query, aliases):
        pass

MyModel.objects.complex_filter(DoNothingQ())

A side effect: My patch prevents builtin Q objects from being wrapped in another Q object when passed to complex_filter(). I'm not sure that's ok.

The cause ist the same as in http://groups.google.com/group/django-users/msg/3e6d910eacb8b542.

Attachments

complex_filter_q.diff (0.6 kB) - added by emulbreh on 05/27/08 08:14:39.
7312.regressiontest.diff (0.9 kB) - added by anonymous on 05/28/08 07:29:23.

Change History

05/27/08 08:14:39 changed by emulbreh

  • attachment complex_filter_q.diff added.

05/28/08 07:29:23 changed by anonymous

  • attachment 7312.regressiontest.diff added.

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

  • keywords set to qsrf-cleanup.
  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

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

  • milestone set to 1.0.

06/26/08 08:11:54 changed by mtredinnick

The patch looks fine. complex_filter() is a bit of an ugly method, though, and definitely not part of the public API, so I'm going to leave out the test. We'll add tests when we fix limit_choices_to, but I'm not sure locking down the behaviour of complex_filter() just yet is the right thing to do. Non-internal code should really only be calling filter() and exclude() (or calling .query.add_q() directly, I guess).

06/26/08 08:25:59 changed by mtredinnick

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

(In [7766]) Fixed #7312 -- Fixed handling of custom Q-like objects in QuerySet?.custom_filter().

This is pretty much internal-use-only code, so doesn't affect public API at all, but it's nice to be able to handle things properly in any case. Patch from emulbreh.


Add/Change #7312 (QuerySet.complex_filter() chokes on custom Q objects (with add_to_query() method))




Change Properties
Action