Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#18593 closed Bug (duplicate)

Admin change list swallows unrelated AttributeErrors from callable display fields

Reported by: Pi Delport Owned by: nobody
Component: contrib.admin Version: 1.4
Severity: Normal Keywords: admin, list_display
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If a callable display field on a model or model admin raises either an AttributeError, the interface currently captures the error, and renders the field as EMPTY_CHANGELIST_VALUE.

This behavior is surprising and confusing when the AttributeError originates in unrelated user code called by the display field: errors like third-party app bugs or missing settings get silenced, and the field's content simply becomes "(None)". There's no hint to a novice about what went wrong, or where to look next.

The code responsible for this is in templatetags/admin_list.py's items_for_result(), around lookup_field(). As far as i can tell, all the valid empty fields cases are covered by results of ObjectDoesNotExist or None, and not AttributeError: a missing attribute specified in list_display normally result in ImproperlyConfigured instead.

If there's no compelling reason to capture AttributeError like this, can it simply be removed from the exception list, and allowed to propagate?

Change History (5)

comment:1 by Pi Delport, 12 years ago

Has patch: set

I added a fix and regression test for this on GitHub: #193.

It turns out the test suite itself contained a latent bug that was being masked by this: the above patch fixes that too.

comment:2 by Aymeric Augustin, 12 years ago

Triage Stage: UnreviewedDesign decision needed

in reply to:  2 comment:3 by Pi Delport, 12 years ago

I found an older ticket for this same bug: #16655.

From the comments, the proposed change was discussed and accepted back then, but needed a test: does this patch resolve that?

comment:4 by Aymeric Augustin, 12 years ago

Resolution: duplicate
Status: newclosed

comment:5 by Aymeric Augustin, 12 years ago

Fixed in [617d077f].

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