Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#18747 closed Bug (duplicate)

Django admin list_display eats AttributeError by mistake

Reported by: liu.dongyuan@… Owned by: tswicegood
Component: contrib.admin Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

When Django admin list_display calling custom method, the exception AttributeError can't be seen.

See the sample snippets below.

class ExampleAdmin(admin.ModelAdmin):
    def example(self, field):
        raise AttributeError
    list_display = ('example',)
class ExampleAdmin(admin.ModelAdmin):
    def example(self, field):
        a = 1
        a.encode("utf8")
    list_display = ('example',)

Attachments (1)

18747.diff (894 bytes) - added by thikonom 3 years ago.

Download all attachments as: .zip

Change History (5)

Changed 3 years ago by thikonom

comment:1 Changed 3 years ago by thikonom

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to thikonom
  • Patch needs improvement unset
  • Status changed from new to assigned

Since i suppose the AttributeError is catched this way by design,
i amended the code to distinguish between the Exception raise by the model itself or by any other object

comment:2 Changed 3 years ago by tswicegood

  • Needs tests set
  • Owner changed from thikonom to tswicegood
  • Patch needs improvement set
  • Status changed from assigned to new
  • Triage Stage changed from Unreviewed to Accepted

Definitely something we should probably handle, though I think there's a better way to figure out where the exception came from. Taking a stab at the patch.

comment:3 Changed 3 years ago by tswicegood

  • Resolution set to duplicate
  • Status changed from new to closed

There are actually a few older versions of this:

Going to close as a duplicate.

comment:4 Changed 3 years ago by aaugustin

Fixed in [617d077f].

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