Opened 14 years ago

Closed 13 years ago

Last modified 12 years ago

#12004 closed (fixed)

Registering abstract model with admin gives confusing / misleading error

Reported by: Matt Smalley <matt.smalley@…> Owned by: nobody
Component: contrib.admin Version: 1.1
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

It makes perfect sense that an abstract model cannot be registered with admin. However, the abstract model is listed with the rest and there is no error until the page for that model is requested from the admin interface. Doing so gives:

'str' object has no attribute '_default_manager'

This is a bit mysterious, and IMO would be better handled at the time of registering the model with something more explicit. Also, since this error occurs in some other hard-to-identify cases (see #10405, among others), I spent a lot of time going down blind alleys in search of the source of the problem.

Attachments (4)

fix12004.patch (4.6 KB ) - added by Matthias Kestenholz 13 years ago.
12004_admin_abstract_models.py (3.5 KB ) - added by Julien Phalip 13 years ago.
12004_admin_abstract_models.diff (3.5 KB ) - added by Julien Phalip 13 years ago.
Patch with correct diff extension
12004_admin_abstract_models.2.diff (2.5 KB ) - added by Julien Phalip 13 years ago.
Simplified test and move it to a better home (regressiontests/admin_registration/)

Download all attachments as: .zip

Change History (9)

comment:1 by Russell Keith-Magee, 14 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Matthias Kestenholz, 13 years ago

Has patch: set

This patch changes admin.site.register to raise an ImproperlyConfigured exception if someone tries to register an abstract model with the administration.

Unit test included.

by Matthias Kestenholz, 13 years ago

Attachment: fix12004.patch added

by Julien Phalip, 13 years ago

by Julien Phalip, 13 years ago

Patch with correct diff extension

comment:3 by Julien Phalip, 13 years ago

milestone: 1.3
Triage Stage: AcceptedReady for checkin

Thank you mk for your patch. I've just updated the message in the exception and simplified the tests (no need to have a special url or AdminSite object).

by Julien Phalip, 13 years ago

Simplified test and move it to a better home (regressiontests/admin_registration/)

comment:4 by Russell Keith-Magee, 13 years ago

Resolution: fixed
Status: newclosed

In [15636]:

Fixed #12004 -- Improved error reporting when an abstract class is registered with the admin. Thanks to Matt Smalley for the report, and to mk and Julien Phalip for the patch.

comment:5 by Jacob, 12 years ago

milestone: 1.3

Milestone 1.3 deleted

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