google-code-export / sct-project

Automatically exported from code.google.com/p/sct-project
1 stars 1 forks source link

community/context_processors.py: 'NoneType' object does not support item assignment #173

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In line 21 (file community/context_processors.py) is an assignment
(sphdata['installed_apps'] = settings.INSTALLED_APPS) without testing if
sphdata is not None. Function get_current_sphdata() (from
community/middleware) may returns None.

I do not know why it returns None in my case (I suppose I have made a
mistake somewhere in settings, though I have gone through tutorial) but it
does. :-)

Original issue reported on code.google.com by arr...@gmail.com on 30 Sep 2009 at 12:06

GoogleCodeExporter commented 9 years ago
have you added the ThreadLocalsMiddleware to the middlewares in your 
settings.py?

Original comment by herbert....@gmail.com on 30 Sep 2009 at 12:12

GoogleCodeExporter commented 9 years ago
Yes. These are my middlewares:
MIDDLEWARE_CLASSES = (
    'jakakasa.sphene.community.middleware.ThreadLocals',
    #'jakakasa.sphene.community.middleware.MultiHostMiddleware',
    'jakakasa.sphene.community.middleware.GroupMiddleware',
    #'jakakasa.sphene.community.middleware.StatsMiddleware',
    #'jakakasa.sphene.community.middleware.LastModified',
    #'jakakasa.sphene.community.middleware.PermissionDeniedMiddleware',

    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.middleware.doc.XViewMiddleware',
)

I have also tried with uncommented lines with same effect. The problem is in
'_thread_locals' (file community/middleware/py) - it does not have attribute 
'request'.

Original comment by arr...@gmail.com on 30 Sep 2009 at 12:25

GoogleCodeExporter commented 9 years ago
well, it does have the attribute if the middleware is called correctly:
class ThreadLocals(object):
    """Middleware that gets various objects from the
    request object and saves them in thread local storage."""
    def process_request(self, request):
        _thread_locals.request = request
        _thread_locals.user = getattr(request, 'user', None)
        _thread_locals.sphdata = { }

maybe the problem is, that you use a different import.. can you try adapting 
your
python path so that you can use 'sphene.community.middleware.ThreadLocals' ?

Original comment by herbert....@gmail.com on 30 Sep 2009 at 12:31

GoogleCodeExporter commented 9 years ago
I think I found where is the problem. Class ThreadLocals create its own 
instance of
_thread_locals variable. I checked id of _thread_locals before request 
assignment and
get_current_request() and they are different.

I am using 2.6.2 under linux.

Original comment by arr...@gmail.com on 30 Sep 2009 at 1:08

GoogleCodeExporter commented 9 years ago
try changing the way you specify the class in MIDDLEWARE_CLASSES, and it should 
be
the same instance ...

Original comment by herbert....@gmail.com on 30 Sep 2009 at 1:11

GoogleCodeExporter commented 9 years ago
You are right. After this change everything works fine.

Thanks a lot.

Original comment by arr...@gmail.com on 30 Sep 2009 at 1:23

GoogleCodeExporter commented 9 years ago
great :) i'll close the issue

Original comment by herbert....@gmail.com on 30 Sep 2009 at 2:43