Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#15158 closed (fixed)

Server-crashing error: local variable 'loader_name' referenced before assignment

Reported by: Gabriel Farrell Owned by: Ramiro Morales
Component: Core (Other) Version: dev
Severity: Keywords: regression
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Getting the following fatal crash traceback when visiting a page pointing at a missing template:

Traceback (most recent call last):

File "/usr/local/lib/python2.6/dist-packages/django/core/servers/basehttp.py", line 282, in run

self.result = application(self.environ, self.start_response)

File "/usr/local/lib/python2.6/dist-packages/django/contrib/staticfiles/handlers.py", line 74, in call

return self.application(environ, start_response)

File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/wsgi.py", line 273, in call

response = self.get_response(request)

File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 169, in get_response

response = self.handle_uncaught_exception(request, resolver, sys.exc_info())

File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 203, in handle_uncaught_exception

return debug.technical_500_response(request, *exc_info)

File "/usr/local/lib/python2.6/dist-packages/django/views/debug.py", line 59, in technical_500_response

html = reporter.get_traceback_html()

File "/usr/local/lib/python2.6/dist-packages/django/views/debug.py", line 105, in get_traceback_html

'loader': loader_name,

UnboundLocalError: local variable 'loader_name' referenced before assignment

Attachments (1)

15158.1.diff (1.5 KB ) - added by Ramiro Morales 14 years ago.
Proposed fix for the issue

Download all attachments as: .zip

Change History (11)

comment:1 by Gabriel Farrell, 14 years ago

Sorry, here's the traceback preformatted:

Traceback (most recent call last):

  File "/usr/local/lib/python2.6/dist-packages/django/core/servers/basehttp.py", line 282, in run
    self.result = application(self.environ, self.start_response)

  File "/usr/local/lib/python2.6/dist-packages/django/contrib/staticfiles/handlers.py", line 74, in __call__
    return self.application(environ, start_response)

  File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/wsgi.py", line 273, in __call__
    response = self.get_response(request)

  File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 169, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())

  File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 203, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)

  File "/usr/local/lib/python2.6/dist-packages/django/views/debug.py", line 59, in technical_500_response
    html = reporter.get_traceback_html()

  File "/usr/local/lib/python2.6/dist-packages/django/views/debug.py", line 105, in get_traceback_html
    'loader': loader_name,

UnboundLocalError: local variable 'loader_name' referenced before assignment

comment:2 by Gabriel Farrell, 14 years ago

Needs tests: set

comment:3 by Ramiro Morales, 14 years ago

Keywords: regression added
milestone: 1.3
Owner: changed from nobody to Ramiro Morales
Status: newassigned
Triage Stage: UnreviewedAccepted

Oops, that was me in r15252. Thanks for the report.

comment:4 by Ramiro Morales, 14 years ago

@gsf:

It seems one of the template loaders you have listed in your TEMPLATE_LOADERS setting has problems when it is going to be loaded. Can you verify this and post the value of such setting?

by Ramiro Morales, 14 years ago

Attachment: 15158.1.diff added

Proposed fix for the issue

comment:5 by Ramiro Morales, 14 years ago

Has patch: set

comment:6 by Jannis Leidel, 14 years ago

Triage Stage: AcceptedReady for checkin

in reply to:  4 comment:7 by Ramiro Morales, 14 years ago

Replying to ramiro:

@gsf:

It seems one of the template loaders you have listed in your TEMPLATE_LOADERS setting has problems when it is going to be loaded. Can you verify this and post the value of such setting?

No, at that point the template loader loadability has already been verified in some other parts of the code (find_template, find_template_loader) so the exception isn't getting raised there. The problem is that the get_template_sources() Loader method isn't part of the required API of a Loader, only the filesystem-based and app-dir loaders have it in the same way as the their counterpart old callable-based loaders pre-r11826 were the only having the get_template_sources() function. The AttributeError is being raised at that point (possibly because the OP is using the egg loader or a third party loader.)

I'm going to fix this with the proposed patch that maintains the status quo. Users using loaders that don't implement Loader.get_template_sources() won't get a list of templates tried in the debug error page just like happened with callable-based loader that didn't implement the get_template_sources() function.

comment:8 by Ramiro Morales, 14 years ago

Resolution: fixed
Status: assignedclosed

Fixed in r15360 (and r15361 for the 1.2.X branch).

in reply to:  4 comment:9 by Gabriel Farrell, 14 years ago

Replying to ramiro:

@gsf:

It seems one of the template loaders you have listed in your TEMPLATE_LOADERS setting has problems when it is going to be loaded. Can you verify this and post the value of such setting?

Sorry I missed this earlier. It looks like the error was caused by a combination of a missing template and the old style for template loaders in my settings file, i.e.:

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.load_template_source',
    'django.template.loaders.app_directories.load_template_source',
)

comment:10 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

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