Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#21129 closed Bug (fixed)

Little change of admin filter URL throws AttributeError

Reported by: Tuttle Owned by: CodenameTim
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


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/ in lookup_allowed
                    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 =
                    rel_name = field.rel.get_related_field().name
                elif isinstance(field, RelatedObject):
                    model = field.model
                    rel_name =
                    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 Changed 2 years ago by timo

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

I guess the solution here would be to ignore the invalid parameter rather than throw a server error?

comment:2 Changed 2 years ago by CodenameTim

  • Cc schillingt@… added
  • Has patch set
  • Owner changed from nobody to CodenameTim
  • Status changed from new to 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


comment:3 Changed 2 years ago by Tim Graham <timograham@…>

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

In 5381317fe37d50384ef9a3bf3fb6b64ff4e9215c:

Fixed #21129 -- Prevented admin filter params modifications from throwing an exception.

Thanks Tuttle for the report.

comment:4 Changed 2 years ago by Tim Graham <timograham@…>

In e5b0f5b95d49c33f5431cf4060705b5e59ec69d4:

[1.6.x] Fixed #21129 -- Prevented admin filter params modifications from throwing an exception.

Thanks Tuttle for the report.

Backport of 5381317fe3 from master

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