Opened 14 years ago

Closed 13 years ago

#14639 closed (fixed)

admin.site.register() does not check if the model is abstract (gives weird error)

Reported by: Diederik van der Boor Owned by: nobody
Component: contrib.admin Version: dev
Severity: Keywords: error-messages
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When an abstract model is registered with admin.site.register() it produces the following error later on:

type object '...' has no attribute '_default_manager'

This error does not make much sense unless you're already have more intimate knowledge of the framework.
To ease the learning curve of new developers, I think it would make sense to check whether the model is abstract or not.

Attachments (1)

14639-admin-site-prevent-abstract-registration.patch (2.2 KB ) - added by Craig de Stigter 13 years ago.
Prevent registration of abstract models with AdminSite.register(). Includes regression test

Download all attachments as: .zip

Change History (6)

comment:1 by Diederik van der Boor, 14 years ago

Addition: it produces even more weird errors in the admin_tools dashboard, when viewing a specific app:

Caught AttributeError while rendering: 'NoneType' object has no attribute '_meta'

which happens somewhere in the contenttypes framework:

File "/usr/lib/python2.6/site-packages/admin_tools/dashboard/templatetags/admin_tools_dashboard_tags.py" in admin_tools_render_dashboard_css
  90.         dashboard = get_dashboard(context, location)
File "/usr/lib/python2.6/site-packages/admin_tools/dashboard/utils.py" in get_dashboard
  21.         return get_app_index_dashboard(context)
File "/usr/lib/python2.6/site-packages/admin_tools/dashboard/utils.py" in get_app_index_dashboard
  71.     return getattr(mod, inst)(app_title, model_list)
File "/usr/lib/python2.6/site-packages/admin_tools/dashboard/dashboards.py" in __init__
  304.             include_list=self.get_app_content_types(),
File "/usr/lib/python2.6/site-packages/admin_tools/dashboard/dashboards.py" in get_app_content_types
  184.                 in self.get_app_model_classes()]
File "/usr/lib/python2.6/site-packages/django/contrib/contenttypes/models.py" in get_for_model
  40.             self._add_to_cache(self.db, ct)
File "/usr/lib/python2.6/site-packages/django/contrib/contenttypes/models.py" in _add_to_cache
  70.         key = (model._meta.app_label, model._meta.object_name.lower())

comment:2 by rasca, 13 years ago

Triage Stage: UnreviewedAccepted
Version: 1.2SVN

I can confirm that it outputs this error.

by Craig de Stigter, 13 years ago

Prevent registration of abstract models with AdminSite.register(). Includes regression test

comment:3 by Craig de Stigter, 13 years ago

Has patch: set

comment:4 by Jannis Leidel, 13 years ago

Needs tests: set

comment:5 by Julien Phalip, 13 years ago

Resolution: fixed
Status: newclosed

This was fixed in [15636].

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