Code

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#15158 closed (fixed)

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

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

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 3 years ago.
Proposed fix for the issue

Download all attachments as: .zip

Change History (11)

comment:1 Changed 3 years ago by gsf

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 Changed 3 years ago by gsf

  • Needs tests set

comment:3 Changed 3 years ago by ramiro

  • Keywords regression added
  • milestone set to 1.3
  • Owner changed from nobody to ramiro
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted

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

comment:4 follow-ups: Changed 3 years ago by 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?

Changed 3 years ago by ramiro

Proposed fix for the issue

comment:5 Changed 3 years ago by ramiro

  • Has patch set

comment:6 Changed 3 years ago by jezdez

  • Triage Stage changed from Accepted to Ready for checkin

comment:7 in reply to: ↑ 4 Changed 3 years ago by ramiro

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 Changed 3 years ago by ramiro

  • Resolution set to fixed
  • Status changed from assigned to closed

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

comment:9 in reply to: ↑ 4 Changed 3 years ago by gsf

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 Changed 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.