#21129 closed Bug (fixed)
Little change of admin filter URL throws AttributeError
Reported by: | Vlada Macek | Owned by: | Timothy Schilling |
---|---|---|---|
Component: | contrib.admin | Version: | 1.5 |
Severity: | Normal | Keywords: | |
Cc: | schillingt@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
A list_filter for FK creates a query string <field>__id__exact
. Changing 'exact' to anything else appears to throw:
AttributeError: 'NoneType' object has no attribute 'to'
Tested on 1.5.4 and 1.4.x.
.../django/contrib/admin/options.py in lookup_allowed try: field, _, _, _ = model._meta.get_field_by_name(part) except FieldDoesNotExist: # Lookups on non-existent fields are ok, since they're ignored # later. return True if hasattr(field, 'rel'): >>> model = field.rel.to rel_name = field.rel.get_related_field().name elif isinstance(field, RelatedObject): model = field.model rel_name = model._meta.pk.name else: rel_name = None ▼ Local vars Variable Value rel_name u'id' self <project.apps.calendar.admin.BusyAdmin object at 0xb523768c> parts [u'site', u'id', u'anything'] value u'5' field <django.db.models.fields.AutoField: id> part u'id' lookup u'site__id__anything' model <class 'django.contrib.sites.models.Site'> _ False
Change History (4)
comment:1 by , 11 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 11 years ago
Cc: | added |
---|---|
Has patch: | set |
Owner: | changed from | to
Status: | new → assigned |
Alright I think I have a decent solution. One thing I want to bring up is that when you attempt to use a URL that has a bad filter, it will redirect you to the same page but with the query string set to ?e=1
. I looked this up and it looks like it means that an error occurred. Is this the correct response? I suppose it lets the user know that they requested a bad url, but it eliminates the query string they had previously.
I created a simple test to verify this new functionality in the method lookup_allowed
Commit: https://github.com/tim-schilling/django/commit/a143239afd9faaa3317e1447e761faa02a778056
comment:3 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
I guess the solution here would be to ignore the invalid parameter rather than throw a server error?