Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #357 from tswicegood/fix-list-attr

Removed admin's swallowing of AttributeError (#16655, #18593, #18747)
  • Loading branch information...
commit 617d077f1f5be6cfb67a1f4f9ab0334f3c793e4c 2 parents d823bb7 + ccd1bb0
@aaugustin aaugustin authored
View
2  django/contrib/admin/templatetags/admin_list.py
@@ -182,7 +182,7 @@ def items_for_result(cl, result, form):
row_class = ''
try:
f, attr, value = lookup_field(field_name, result, cl.model_admin)
- except (AttributeError, ObjectDoesNotExist):
+ except ObjectDoesNotExist:
result_repr = EMPTY_CHANGELIST_VALUE
else:
if f is None:
View
16 tests/regressiontests/admin_views/admin.py
@@ -27,11 +27,14 @@
Album, Question, Answer, ComplexSortedPerson, PrePopulatedPostLargeSlug,
AdminOrderedField, AdminOrderedModelMethod, AdminOrderedAdminMethod,
AdminOrderedCallable, Report, Color2, UnorderedObject, MainPrepopulated,
- RelatedPrepopulated, UndeletableObject)
+ RelatedPrepopulated, UndeletableObject, Simple)
def callable_year(dt_value):
- return dt_value.year
+ try:
+ return dt_value.year
+ except AttributeError:
+ return None
callable_year.admin_order_field = 'date'
@@ -575,6 +578,14 @@ def change_view(self, *args, **kwargs):
return super(UndeletableObjectAdmin, self).change_view(*args, **kwargs)
+def callable_on_unknown(obj):
+ return obj.unknown
+
+
+class AttributeErrorRaisingAdmin(admin.ModelAdmin):
+ list_display = [callable_on_unknown, ]
+
+
site = admin.AdminSite(name="admin")
site.register(Article, ArticleAdmin)
site.register(CustomArticle, CustomArticleAdmin)
@@ -648,6 +659,7 @@ def change_view(self, *args, **kwargs):
site.register(AdminOrderedAdminMethod, AdminOrderedAdminMethodAdmin)
site.register(AdminOrderedCallable, AdminOrderedCallableAdmin)
site.register(Color2, CustomTemplateFilterColorAdmin)
+site.register(Simple, AttributeErrorRaisingAdmin)
# Register core models we need in our tests
from django.contrib.auth.models import User, Group
View
1  tests/regressiontests/admin_views/customadmin.py
@@ -49,3 +49,4 @@ def queryset(self, request):
site.register(models.ChapterXtra1, base_admin.ChapterXtra1Admin)
site.register(User, UserLimitedAdmin)
site.register(models.UndeletableObject, base_admin.UndeletableObjectAdmin)
+site.register(models.Simple, base_admin.AttributeErrorRaisingAdmin)
View
6 tests/regressiontests/admin_views/models.py
@@ -649,3 +649,9 @@ class UndeletableObject(models.Model):
Refs #10057.
"""
name = models.CharField(max_length=255)
+
+
+class Simple(models.Model):
+ """
+ Simple model with nothing on it for use in testing
+ """
View
16 tests/regressiontests/admin_views/tests.py
@@ -46,7 +46,7 @@
OtherStory, ComplexSortedPerson, Parent, Child, AdminOrderedField,
AdminOrderedModelMethod, AdminOrderedAdminMethod, AdminOrderedCallable,
Report, MainPrepopulated, RelatedPrepopulated, UnorderedObject,
- UndeletableObject)
+ Simple, UndeletableObject)
ERROR_MESSAGE = "Please enter the correct username and password \
@@ -578,6 +578,20 @@ def test_change_view_with_show_delete_extra_context(self):
(self.urlbit, instance.pk))
self.assertNotContains(response, 'deletelink')
+ def test_allows_attributeerror_to_bubble_up(self):
+ """
+ Ensure that AttributeErrors are allowed to bubble when raised inside
+ a change list view.
+
+ Requires a model to be created so there's something to be displayed
+
+ Refs: #16655, #18593, and #18747
+ """
+ Simple.objects.create()
+ with self.assertRaises(AttributeError):
+ self.client.get('/test_admin/%s/admin_views/simple/' % self.urlbit)
+
+
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class AdminViewFormUrlTest(TestCase):
urls = "regressiontests.admin_views.urls"
Please sign in to comment.
Something went wrong with that request. Please try again.