#23525: admin/docs/filters|tags __file__ attribute errors for egg extensions
-------------------------------------+-------------------------------------
Reporter: welbornprod | Owner: nobody
Type: Bug | Status: new
Component: contrib.admindocs | Version: 1.7
Severity: Normal | Resolution:
Keywords: __file__ | Triage Stage:
AttributeError filters tags | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by welbornprod):
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Old description:
> Accessing `hostname.com/admin/doc/filters` and
> `hostname.com/admin/doc/tags` causes an Internal Server Error on Django
> 1.7.
>
> 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:
> {{{#!python
> 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:
>
> {{{#!python
> try:
> # ...same code from above.
> except OSError, AttributeError:
> libraries = []
> }}}
New description:
Accessing `hostname.com/admin/doc/filters` and
`hostname.com/admin/doc/tags` causes an Internal Server Error on Django
1.7.
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:
{{{#!python
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:
{{{#!python
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.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/23525#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/069.be5783915c91e5eeba6da8ad9b53f042%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.