Django - Weird behaviour of sessions variables with Apache

Posted by Étienne Loks on Stack Overflow See other posts from Stack Overflow or by Étienne Loks
Published on 2012-10-25T22:56:18Z Indexed on 2012/10/25 23:00 UTC
Read the original article Hit count: 131

Filed under:
|

In a Menu class with Section children, each Section has an available attribute. This attribute is initialized during the instance creation. The process of getting the availability is not trivial, so I stock a Menu instance for each user in a session variable.

With the Django embedded webserver this works well. But when I deploy the application on an Apache webserver I can observe a very weird behavior. Once authentified, a click on a link or a refreshment of the page and the availability of each Section seems to be forgotten (empty menu but in the log file I can see that all Sections are here) then a new refresh on the page the availability is back, a new refresh the menu disappears once again, etc. There is no cache activated on the web server.

The menu is initialized in a context processor.

def get_base_context(request):                                                    
    if 'MENU' not in request.session or \                                         
       not request.session['MENU'].childs or\                                     
       request.session['MENU'].user != request.user:                              
        _menu = Menu(request.user)                                                
        _menu.init()                                                              
        request.session['MENU'] = _menu
    (...)

I have no idea what could cause such a behavior. Any clue?

© Stack Overflow or respective owner

Related posts about django

Related posts about session-variables