Permalink
Browse files

Verify that the field is not None before trying to access the rel pro…

…perty. Rel #21129.
  • Loading branch information...
1 parent 656bfe4 commit a143239afd9faaa3317e1447e761faa02a778056 @tim-schilling committed Sep 25, 2013
Showing with 16 additions and 0 deletions.
  1. +4 −0 django/contrib/admin/options.py
  2. +12 −0 tests/modeladmin/tests.py
View
4 django/contrib/admin/options.py
@@ -348,6 +348,10 @@ def lookup_allowed(self, lookup, value):
# later.
return True
if hasattr(field, 'rel'):
+ if field.rel is None:
+ # This property or relation doesn't exist, but it's allowed
+ # since it's ignored later.
+ return True
model = field.rel.to
rel_name = field.rel.get_related_field().name
elif isinstance(field, RelatedObject):
View
12 tests/modeladmin/tests.py
@@ -95,6 +95,18 @@ def get_fieldsets(self, request, obj=None):
form = ma.get_formset(None).form
self.assertEqual(form._meta.fields, ['day', 'transport'])
+ def test_lookup_allowed_allows_nonexistent_lookup(self):
+ """
+ Ensure that a lookup_allowed allows a parameter
+ whose field lookup doesn't exist.
+ Refs #21129.
+ """
+ class BandAdmin(ModelAdmin):
+ fields = ['name']
+
+ ma = BandAdmin(Band, self.site)
+ self.assertTrue(ma.lookup_allowed('name__nonexistent', 'returns True'))
+
def test_field_arguments(self):
# If we specify the fields argument, fieldsets_add and fielsets_change should
# just stick the fields into a formsets structure and return it.

0 comments on commit a143239

Please sign in to comment.