Ask Your Question

Why am I getting a Nonetype error in the code, when the same statment works in a logging directive?

asked 2013-05-03 14:27:08 -0600

mrB's avatar

updated 2013-05-08 15:02:18 -0600

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/ 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/ TIME: 2013-05-03 13:22:53,209 MSG: 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?


Turns out, my Memcache instant had gotten turned off somehow. I restarted Memcache and it started working.

edit retag flag offensive close merge delete


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 the None.

Evgeny's avatar Evgeny  ( 2013-05-03 14:36:54 -0600 )edit

What are your cache settings?

Evgeny's avatar Evgeny  ( 2013-05-03 14:56:39 -0600 )edit

CACHE_BACKEND = 'django.core.cache.backends.memcached.MemcachedCache' #needed for django-keyedcache


#sets a special timeout for livesettings if you want to make them different LIVESETTINGS_CACHE_TIMEOUT = CACHE_TIMEOUT KEY_PREFIX = 'askpaleo' #make this unique


mrB's avatar mrB  ( 2013-05-06 20:09:56 -0600 )edit

Maybe your cache is not working? Have you tried locmem cache just for the test?

Evgeny's avatar Evgeny  ( 2013-05-07 16:01:24 -0600 )edit

Turns out, my Memcache instant had gotten turned off somehow. I restarted Memcache and it started working.

mrB's avatar mrB  ( 2013-05-08 15:01:16 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2013-05-03 22:08:40 -0600

Evgeny's avatar

It appears that value of my_settings is None so the assignment will fail. A good question is why this is the case, it should not be. Could you answer my questions in the comments above?

edit flag offensive delete link more


I was able to log all the values of askbot_settings.__dict__ . However assignment to my_settings.askbot_settings.as_dict() does not work.

Why do would the assignment to my_settings not work?

mrB's avatar mrB  ( 2013-05-07 15:58:46 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-05-03 14:27:08 -0600

Seen: 801 times

Last updated: May 08 '13