Exceptions in admin.py can get hidden by an AlreadyRegistered exception
|Reported by:||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Consider the following admin.py file:
from django.contrib import admin from testpro.testapp.models import * admin.site.register(Screenshot) raise Exception("Exception that can be much less obvious than this staged one (like a missed import).")
It's loaded by admin.autodiscover() in urls.py.
Now start the development server in debug mode and access the admin. What happens is this:
- On the first request after starting the dev server our test exception is shown as the response.
ImproperlyConfigured at /admin/ Error while importing URLconf 'testpro.urls': Exception that can be much less obvious than this staged one (like a missed import).
- For every subsequent request this exception is the response:
ImproperlyConfigured at /admin/ Error while importing URLconf 'testpro.urls': The model Screenshot is already registered
Needless to say this can be really frustrating to debug if one does not see the first and correct exception by chance.
Change History (28)
comment:16 Changed 8 years ago by
|Triage Stage:||Design decision needed → Accepted|