general: save session at the very end (#47154)

It's necessary for native django responses as rendering will not go
through CompatWcsPublisher.
This commit is contained in:
Frédéric Péters 2021-05-04 10:18:36 +02:00
parent d27d92dc4e
commit d6816b90ad
2 changed files with 8 additions and 0 deletions

View File

@ -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'):

View File

@ -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