First time here? Check out the FAQ!
0

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

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

hjwp's avatar
31
hjwp
updated 2011-11-23 11:36:57 -0600, asked 2011-11-23 11:27:08 -0600
edit flag offensive 0 remove flag close merge delete

Comments

aha! the exact ordering of the MIDDLEWARE_CLASSES matters!

hjwp's avatar hjwp (2011-11-23 11:44:06 -0600) 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 -0600) edit
add a comment see more comments

2 Answers

1

(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')
hjwp's avatar
31
hjwp
answered 2011-11-23 11:47:25 -0600
edit flag offensive 0 remove flag delete link

Comments

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

Evgeny's avatar Evgeny (2011-11-23 12:08:08 -0600) edit
add a comment see more comments
0

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.

Evgeny's avatar
13.2k
Evgeny
answered 2011-11-23 11:34:10 -0600
edit flag offensive 0 remove flag delete link

Comments

thanks Evgeny - here is our MIDDLEWARE_CLASSES:

hjwp's avatar hjwp (2011-11-23 11:35:16 -0600) 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 -0600) edit
add a comment see more comments