A persistent problem with server-side sessions is the browser state getting out of synchronisation with the application state. This occurs when the browser "back" button is used, or when a form is reloaded (this is logically equivilent to a "back" then a resubmission of the old form state).
One solution to this problem is to maintain a server-side session for each interaction with the browser, rather than a single session per client that is recycled for each interaction. A unique session identifier is stored in a hidden form field, which allows us to retrieve the appropriate version of the session on form submission (the hidden field value is rolled back with the browser state when the "back" button is used, unlike a cookie). This class provides a drop-in replacement for the SessionServerContextMixin and implements this session-per-interaction behaviour.
) |
) |
) |
If an existing session is retrieved it is passed to the decode_session() method (inherited from the superclass). If an exception is raised during decode_session() then the session will be deleted from the server and a new session will be created via the application object new_session() method.
) |
Before saving a session the method calls the superclass encode_session() then calls the put_session() application method to save the session.
) |
) |
Note that this method is also present in the RecorderMixin, so if you inherit from the BranchingSessionMixin class you must define a form_close() method in the derived class which calls this method in both of the super classes.