Django - Weird behaviour of sessions variables with Apache
- by Étienne Loks
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?