From d6816b90adceea9312216791a821ea283c63bf73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 4 May 2021 10:18:36 +0200 Subject: [PATCH] general: save session at the very end (#47154) It's necessary for native django responses as rendering will not go through CompatWcsPublisher. --- wcs/compat.py | 1 + wcs/middleware.py | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/wcs/compat.py b/wcs/compat.py index 65f9c5297..bc90187e0 100644 --- a/wcs/compat.py +++ b/wcs/compat.py @@ -228,6 +228,7 @@ class CompatWcsPublisher(WcsPublisher): # rendering may have altered it (for example a form would add its # token). self.session_manager.finish_successful_request() + request.ignore_session = True # no further changes for name, value in response.generate_headers(): if name in ('Connection', 'Content-Length'): diff --git a/wcs/middleware.py b/wcs/middleware.py index d43c23459..bd69004a3 100644 --- a/wcs/middleware.py +++ b/wcs/middleware.py @@ -91,6 +91,13 @@ class PublisherInitialisationMiddleware(MiddlewareMixin): def process_response(self, request, response): pub = get_publisher() if pub: + request = pub.get_request() + if request and not request.ignore_session: + # it is necessary to save the session one last time as the actual + # rendering may have altered it (for example a form would add its + # token). + pub.session_manager.finish_successful_request() + pub.cleanup() return response