Opened 8 years ago

Closed 7 years ago

#14639 closed (fixed) does not check if the model is abstract (gives weird error)

Reported by: Diederik van der Boor Owned by: nobody
Component: contrib.admin Version: master
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


When an abstract model is registered with 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 8 years ago.
Prevent registration of abstract models with AdminSite.register(). Includes regression test

Download all attachments as: .zip

Change History (6)

comment:1 Changed 8 years ago by Diederik van der Boor

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

comment:2 Changed 8 years ago by rasca

Triage Stage: UnreviewedAccepted
Version: 1.2SVN

I can confirm that it outputs this error.

Changed 8 years ago by Craig de Stigter

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

comment:3 Changed 8 years ago by Craig de Stigter

Has patch: set

comment:4 Changed 8 years ago by Jannis Leidel

Needs tests: set

comment:5 Changed 7 years ago by Julien Phalip

Resolution: fixed
Status: newclosed

This was fixed in [15636].

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