Ask Your Question
0

'WSGIRequest' object has no attribute 'session' - error trying to integrate askbot with our own django app

asked 2011-11-23 11:27:08 -0500

hjwp's avatar

updated 2011-11-23 11:36:57 -0500

Currently getting the following error when moving between askbot pages and our own django app:

'WSGIRequest' object has no attribute 'session'

with traceback ending at

/usr/local/lib/python2.6/dist-packages/Django-1.3.1-py2.6.egg/django/contrib/auth/__init__.py in get_user
    107.     user_id = request.session[SESSION_KEY]

Suspect this is because askbot is using different session middleware to our own - any ideas?

Minimal repro is: go to askbot section of our site (not logged in), click on "log in" link.

here is our MIDDLEWARE_CLASSES from settings.py:

('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'askbot.middleware.anon_user.ConnectToSessionMessagesMiddleware',
 'askbot.middleware.pagesize.QuestionsPageSizeMiddleware',
 'askbot.middleware.cancel.CancelActionMiddleware',
 'django.middleware.transaction.TransactionMiddleware',
 'askbot.middleware.view_log.ViewLogMiddleware',
 'askbot.middleware.spaceless.SpacelessMiddleware')

as far as I can tell, this is merged correctly with the askbot settings.py...

edit retag flag offensive close merge delete

Comments

aha! the exact ordering of the MIDDLEWARE_CLASSES matters!

hjwp's avatar hjwp  ( 2011-11-23 11:44:06 -0500 )edit

It does, we'll need to add checks on the middleware order to the startup tests. Did you change order of the first two? Is the problem fixed?

Evgeny's avatar Evgeny  ( 2011-11-23 11:49:51 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2011-11-23 11:47:25 -0500

hjwp's avatar

(is it rude to answer my own question, when Evgeny actually answered it? still hopefully this will help for clarity):

  • you need to make sure your middlewares are loaded in the right order in settings.py

so, MIDDLEWARE_CLASSES should have been:

('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'askbot.middleware.anon_user.ConnectToSessionMessagesMiddleware',
'askbot.middleware.pagesize.QuestionsPageSizeMiddleware',
'askbot.middleware.cancel.CancelActionMiddleware',
'django.middleware.transaction.TransactionMiddleware',
'askbot.middleware.view_log.ViewLogMiddleware',
'askbot.middleware.spaceless.SpacelessMiddleware')
edit flag offensive delete link more

Comments

Great. When we add the ordering test these issues will go away hopefully.

Evgeny's avatar Evgeny  ( 2011-11-23 12:08:08 -0500 )edit
0

answered 2011-11-23 11:34:10 -0500

Evgeny's avatar

Hi, there is no special session middleware. I am guessing the key is to merge the settings.py correctly for your app and askbot. It is possible that in your case some middlewares are missing or run in incorrect order.

Probably for the debugging purposes you might want to symlink django into current directory and walk with the debugger through the middleware loading stage.

We will improve the auto-tests which run on starting up askbot - that will help with making sure that all necessary pieces are added to the setup.py.

edit flag offensive delete link more

Comments

thanks Evgeny - here is our MIDDLEWARE_CLASSES:

hjwp's avatar hjwp  ( 2011-11-23 11:35:16 -0500 )edit

aha - "incorrect order" was the solution - we've now re-ordered MIDDLEWARE_CLASSES so that they follow the one specified in your settings.py, and that works perfectly now.

hjwp's avatar hjwp  ( 2011-11-23 11:44:57 -0500 )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

1 follower

Stats

Asked: 2011-11-23 11:27:08 -0500

Seen: 6,043 times

Last updated: Nov 23 '11