Why am I getting a Nonetype error in the code, when the same statment works in a logging directive?
I'm trying to get Askbot working in production on Webfaction. I'm not sure what is going on because the app worked fine for a month, then suddenly, it stopped working. I didn't update the askbot code nor did I change anything on the templates.
The Django debug page is showing:
Exception Value: 'NoneType' object does not support item assignment
Exception Location: /home/username/webapps/askbot/askbot-discussion/askbot/context.py in application_settings, line 31
I decided to log the variables to see why I was getting a NoneType exception immediately before the NoneType error is thrown in the code.
import logging
logging.critical("request[LANGUAGE_CODE] :" + getattr(request, 'LANGUAGE_CODE', settings.LANGUAGE_CODE) )
my_settings['LANGUAGE_CODE'] = getattr(request, 'LANGUAGE_CODE', settings.LANGUAGE_CODE)
This logged: /home/username/webapps/askbot/askbot-discussion/askbot/context.py TIME: 2013-05-03 13:22:53,209 MSG: context.py:application_settings:33 request[LANGUAGE_CODE] :en
As you can see, getattr(request, 'LANGUAGE_CODE', settings.LANGUAGE_CODE) return "en" for the logging directive.
I'm at a loss for why I'd be getting a NoneType error, because the getattr() worked fine for logging, but for some reason it fails in the actual code.
What is going on?
+++++++EDIT+++++++
Turns out, my Memcache instant had gotten turned off somehow. I restarted Memcache and it started working.
Comments
That's odd. Is the return value of
askbot_settings.as_dict()
-None
?If so, I recommend you to debug into the
as_dict
function with the pdb and find out why it gives you theNone
.What are your cache settings?
CACHE_BACKEND = 'django.core.cache.backends.memcached.MemcachedCache' #needed for django-keyedcache
CACHE_TIMEOUT = 6000
#sets a special timeout for livesettings if you want to make them different LIVESETTINGS_CACHE_TIMEOUT = CACHE_TIMEOUT KEY_PREFIX = 'askpaleo' #make this unique
CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True
Maybe your cache is not working? Have you tried locmem cache just for the test?
Turns out, my Memcache instant had gotten turned off somehow. I restarted Memcache and it started working.