First time here? Check out the FAQ!
0

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.

mrB's avatar
51
mrB
asked 2013-05-03 14:27:08 -0500, updated 2013-05-08 15:02:18 -0500
edit flag offensive 0 remove flag close merge delete

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

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

What are your cache settings?

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

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

mrB's avatar mrB (2013-05-06 20:09:56 -0500) 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 -0500) 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 -0500) edit
add a comment see more comments

1 Answer

0

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?

Evgeny's avatar
13.2k
Evgeny
answered 2013-05-03 22:08:40 -0500
edit flag offensive 0 remove flag delete link

Comments

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 -0500) edit
add a comment see more comments