As a way to debug this problem, I would subclass the standard Django session middleware (or whatever you're currently using):
django.contrib.sessions.middleware.SessionMiddleware
and wrap process_request
and (probably more importantly) process_response
in some extra logging. Then install your subclassed session middleware in the MIDDLEWARE_CLASSES
, rather than the stock Django one.
You could also validate that session.save()
has actually committed its changes by attempting to read it back. It could be that the problem lies in session-state serialisation, and it's failing on a particular key or value that you're attempting to store.
None of this will fix your problem, but it might help you to establish what's going on.