One situation where this will happen is when a user logs in. The session
id is changed (although the session contents are retained). This is to
prevent one class of security attacks wherein somebody grabs a session
ID from an anonymous user and it remains valid after that user has
logged in (at which point their whole interaction may have switched to
HTTPS, so snooping the session id is harder for the attacker). Since it
doesn't hurt to change the session id, we do it for everybody when a
login occurs.
Similarly, if a user ever logs out, their entire session is flushed and
a new session id will be created.
Other code *may* call the cycle_key() method in the session backends,
but those are the only situations out-of-the-box that will do so.
The point is, you have to be able to handle the session id changing. It
does not identify the session to Django itself (on the server side). The
session object does that and changing the id within the Python object is
valid. The session id is used by the client side to identify the
particular session object for the next request it makes (and that won't
change outside of a particular user's request).
Regards,
Malcolm
I must admit that I don't really understand what you're trying to do
here. However, I would strongly suggest simply following the same logic
as the existing session middleware, which seems to involve setting
things at the last minute.
Personally, though, if I had to work on a system that didn't allow
cookies, I'd try to avoid using Django's session framework. You don't
need sessions very much in many situations (the usual amount is to
record that somebody is logged in and an encrypted form variable of URL
parameter could do that), so you might be trying to solve a small
problem with a large and awkward hammer.
In any case, good luck.
Regards,
Malcolm