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 gravatar image hjwp
31 4 1 6

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

delete close flag offensive retag edit

Comments

aha! the exact ordering of the MIDDLEWARE_CLASSES matters!

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 ( 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 gravatar image hjwp
31 4 1 6

(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')
link publish delete flag offensive edit

Comments

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

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

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

Evgeny gravatar image Evgeny flag of Chile
11009 50 84 182
http://askbot.org/

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.

link publish delete flag offensive edit

Comments

thanks Evgeny - here is our MIDDLEWARE_CLASSES:

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 ( 2011-11-23 11:44:57 -0500 )edit

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Reliable Askbot Hosting

Create your Q&A site at askbot.com. Managed Askbot hosting at just $15/mo. Dedicated hosting, support contracts, consulting services.

create your Q&A site
30 days free trial

Question tools

Follow
1 follower

subscribe to rss feed

Stats

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

Seen: 547 times

Last updated: Nov 23 '11