Opened 16 years ago

Closed 16 years ago

#7113 closed (fixed)

The `ChangeList` does not support custom queryset subclasses

Reported by: jbronn Owned by: Malcolm Tredinnick
Component: contrib.admin Version: dev
Severity: Keywords: admin changelist queryset custom
Cc: andrew@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Custom QuerySet classes (like GeoDjango's GeoQuerySet) can't be merged with regular QuerySet objects (using |, & operators). This problem manifests itself when trying to use search fields with a model that uses a QuerySet subclass:

TypeError ...
Cannot merge querysets of different types ('GeoQuerySet' and 'QuerySet'.

The root cause is that ChangeList hard-codes using QuerySet for the search fields.

In my patch ChangeList takes advantage of existing information to determine the type of queryset being used and store it in a root_query_set_class attribute that is used when performing searches.

Attachments (1)

changelist_custom_qs.diff (1.1 KB ) - added by jbronn 16 years ago.
Allows for custom querysets in the admin changelist.

Download all attachments as: .zip

Change History (7)

by jbronn, 16 years ago

Attachment: changelist_custom_qs.diff added

Allows for custom querysets in the admin changelist.

comment:1 by jbronn, 16 years ago

Summary: The `ChangeList` does not support custom queryset classesThe `ChangeList` does not support custom queryset subclasses

comment:2 by Brian Rosner, 16 years ago

Triage Stage: UnreviewedAccepted
Version: newforms-adminSVN

This looks right to me, but I think this should be applied to trunk first and then merged over to newforms-admin since this code isn't being directly modified in newforms-admin. Otherwise I'd apply this.

comment:3 by Malcolm Tredinnick, 16 years ago

Owner: changed from nobody to Malcolm Tredinnick

comment:4 by Malcolm Tredinnick, 16 years ago

I think you're fixing the symptom, rather than the root problem, with this patch. The problem with the fix here is that it's only the tip of the iceberg. Every single reusable app that uses a QuerySet will have to write similarly awkward code.

The real issue is the tighter restrictions on QuerySet combinations, which has gone a little overboard. The idea behind that change was to prevent people doing silly things like trying to merge a QuerySet and a ValuesQuerySet (which I saw attempted in a post to django-users), not to prevent sensible merges. I didn't think of all the consequences at the time.The problem with the fix here is that it's only the tip of the iceberg. Every single reusable app that uses a QuerySet will have to write similarly awkward code.

I'll rethink the sanity check and possibly remove it entirely (leading to more "GIGO" behaviour) if there's nothing better.

comment:5 by anonymous, 16 years ago

Cc: andrew@… added

comment:6 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

Fixed in [7742] (by removing the overly-strict error checking).

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