Opened 10 years ago
Last modified 10 years ago
#23525 closed Bug
admin/docs/filters|tags __file__ attribute errors for egg extensions — at Version 2
Reported by: | Welborn Productions | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admindocs | Version: | 1.7 |
Severity: | Normal | Keywords: | __file__ AttributeError filters tags |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Accessing hostname.com/admin/doc/filters
and hostname.com/admin/doc/tags
causes an Internal Server Error on Django 1.7. The cause is modules that have no __file__
attribute.
In django/contrib/admindocs/views.py
, the function load_all_installed_template_libraries()
already gracefully fails on OSError
when finding python files. However, when the module being checked has no __file__
attribute the error bubbles up and causes an Internal Server Error.
Someone on django-users suggested that it may be because some extensions are installed as eggs. I've attached a naive patch that simply adds AttributeError
to the caught exceptions, causing the function to fail gracefully instead of letting it bubble up.
The code that triggers the error:
try: libraries = [ os.path.splitext(p)[0] for p in os.listdir(os.path.dirname(upath(mod.__file__))) if p.endswith('.py') and p[0].isalpha() ] except OSError: libraries = []
I've simply added another error to that block:
try: # ...same code from above. except (OSError, AttributeError): libraries = []
I thought about refactoring this and maybe expanding the for-loop so AttributeError
is only caught where needed, but chose instead to make the least invasive change possible.
Change History (3)
by , 10 years ago
Attachment: | django_admindocs_filter.patch added |
---|
comment:1 by , 10 years ago
Description: | modified (diff) |
---|
comment:2 by , 10 years ago
Description: | modified (diff) |
---|
Fixed patch for file AttributeError (naive fix).