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
|
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.
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.