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.

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
mrB's avatar
51
mrB
asked 11 years ago, updated 11 years ago

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 (11 years ago)

What are your cache settings?

Evgeny's avatar Evgeny (11 years ago)

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 (11 years ago)

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

Evgeny's avatar Evgeny (11 years ago)

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

mrB's avatar mrB (11 years ago)
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?

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
Evgeny's avatar
13.2k
Evgeny
answered 11 years ago
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 (11 years ago)
see more comments