A couple users complained that they couldn't get to their authentication settings page on OSQA. They receive a 500 error. See Screenshot But, it is only after they go through the "I Forgot My Password" or after changing their password.
Looking at the log, the error specifically is:
UnboundLocalError: local variable name 'name' referenced before assignment
Has anyone else experienced this? If so, how do I fix it.
Thank you in advance for your help.!!
The Stack Trace from the log reads as follows (Sorry for the poor formatting):
DIRECTORY/forum/templatetags/extra_tags.py TIME: 2012-12-13 09:23:31,419 MSG:extra_tags.py:render:312 Error in declare tag, when evaluating: questions.children_count('answer')
DIRECTORY/apps/django/lib/python2.6/site-packages/django/core/handlers/base.py TIME: 2012-12-14 12:40:31,086 MSG: base.py:handle_uncaught_exception:209 Internal Server Error: /osqa/account/9/authsettings/
Traceback (most recent call last):
File "DIRECTORY/apps/django/lib/python2.6/site-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "DIRECTORY/apps/osqa/forum/views/auth.py", line 348, in auth_settings
'name': name,
UnboundLocalError: local variable 'name' referenced before assignment
DIRECTORY/apps/osqa/forum/views/meta.py TIME: 2012-12-14 12:40:31,093 MSG: meta.py:error_handler:200
error executing request:
PATH: /osqa/account/9/authsettings/
USER: USER (1)
METHOD: GET
POST PARAMETERS:
None
GET PARAMETERS:
None
HTTP HEADERS:
mod_wsgi.listener_port: 8080
HTTP_REFERER: URL/osqa/users/9/USER
mod_wsgi.listener_host:
SERVER_SOFTWARE: Apache
SCRIPT_NAME: /osqa
mod_wsgi.handler_script:
SERVER_SIGNATURE:
REQUEST_METHOD: GET
PATH_INFO: /account/9/authsettings/
SERVER_PROTOCOL: HTTP/1.1
QUERY_STRING:
HTTP_ACCEPT_CHARSET: ISO-8859-1,utf-8;q=0.7,*;q=0.3
HTTP_USER_AGENT: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11
HTTP_CONNECTION: keep-alive
HTTP_COOKIE: sessionid=REDACTED; csrftoken=REDACTED
SERVER_NAME: SERVERNAME
REMOTE_ADDR: SERVERIP
mod_wsgi.request_handler: wsgi-script
wsgi.url_scheme: http
PATH_TRANSLATED: DIRECTORY/apache2/htdocs/account/9/authsettings/
SERVER_PORT: 8080
wsgi.multiprocess: True
mod_wsgi.input_chunked: 0
SERVER_ADDR: SERVERIP
DOCUMENT_ROOT: DIRECTORY/apache2/htdocs
mod_wsgi.process_group:
SCRIPT_FILENAME: DIRECTORY/apps/osqa/scripts/osqa.wsgi
SERVER_ADMIN: you@example.com
wsgi.input: <mod_wsgi.Input object at 0x46feab0>
HTTP_DNT: 1
HTTP_HOST: SERVER:8080
wsgi.multithread: False
mod_wsgi.callable_object: application
REQUEST_URI: /osqa/account/9/authsettings/
HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
wsgi.version: (1, 1)
GATEWAY_INTERFACE: CGI/1.1
wsgi.run_once: False
wsgi.errors: <mod_wsgi.Log object at 0x487c4f0>
REMOTE_PORT: 51455
HTTP_ACCEPT_LANGUAGE: en-US,en;q=0.8
mod_wsgi.version: (3, 3)
mod_wsgi.application_group: localhost:8080|/osqa
mod_wsgi.script_reloading: 1
wsgi.file_wrapper: <built-in method file_wrapper of mod_wsgi.Adapter object at 0x47bf0a8>
CSRF_COOKIE: REDACTED
HTTP_ACCEPT_ENCODING: gzip,deflate,sdch
COOKIES:
csrftoken: REDACTED
sessionid: REDACTED
EXCEPTION INFO:
Traceback (most recent call last):
File "DIRECTORY/apps/django/lib/python2.6/site-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "DIRECTORY/apps/osqa/forum/views/auth.py", line 348, in auth_settings
'name': name,
UnboundLocalError: local variable 'name' referenced before assignment
Looking at the source code of osqa
, here's what can be found around the lines where you're having an issue (the line numbers differ from yours, but that's probably due to a version difference):
347 for k in auth_keys:
348 provider = AUTH_PROVIDERS.get(k.provider, None)
349
350 if provider is not None:
351 name = "%s: %s" % (provider.context.human_name, provider.context.readable_key(k))
352 else:
353 from forum.authentication.base import ConsumerTemplateContext
354 "unknown: %s" % ConsumerTemplateContext.readable_key(k)
355
356 auth_keys_list.append({
357 'name': name,
358 'id': k.id
359 })
Looks like at line 354, we should have name = "unknown: %s" % ConsumerTemplateContext.readable_key(k)
, but someone forgot that name =
.
I can't be 100% sure about this, as I am not really knowledgeable in osqa
, but this statement doesn't do anything otherwise if we leave it like it is. Additionally, your bug is 100% reproductible provided you can identify why k.provider
isn't in AUTH_PROVIDERS
, which I guess has to be pretty uncommon.
You might want to file a bug at osqa
's bug tracker. To solve your issue in the shorter term, you could:
provider
is None
. (Apparently, the issue caused by there being and auth_key
for the current user
that doesn't correspond to any of AUTH_PROVIDERS
).