Code

Opened 5 years ago

Closed 3 years ago

Last modified 3 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: UI/UX:

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 mk 4 years ago.
12004_admin_abstract_models.py (3.5 KB) - added by julien 3 years ago.
12004_admin_abstract_models.diff (3.5 KB) - added by julien 3 years ago.
Patch with correct diff extension
12004_admin_abstract_models.2.diff (2.5 KB) - added by julien 3 years ago.
Simplified test and move it to a better home (regressiontests/admin_registration/)

Download all attachments as: .zip

Change History (9)

comment:1 Changed 4 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 4 years ago by mk

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

Changed 4 years ago by mk

Changed 3 years ago by julien

Changed 3 years ago by julien

Patch with correct diff extension

comment:3 Changed 3 years ago by julien

  • milestone set to 1.3
  • Triage Stage changed from Accepted to Ready 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).

Changed 3 years ago by julien

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

comment:4 Changed 3 years ago by russellm

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

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 Changed 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.