changeset 1193:aee3d8fa679f

pages: fixed cached data when `url_cache` is used: `request.template_data` and `request.data` where cached using a shallow copy, causing trouble when a mutable object was used. This has been fixed by using a deepcopy, which should not be a resource issue as `request.data` and `request.template_data` should contain a few data in most cases.
author Goffi <goffi@goffi.org>
date Wed, 12 Jun 2019 20:05:45 +0200
parents 7b05ebc46141
children bed008b65d7c
files libervia/server/pages.py
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libervia/server/pages.py	Wed Jun 12 09:12:09 2019 +0200
+++ b/libervia/server/pages.py	Wed Jun 12 20:05:45 2019 +0200
@@ -39,6 +39,7 @@
 import urllib
 import time
 import hashlib
+import copy
 
 log = getLogger(__name__)
 
@@ -82,18 +83,18 @@
     def __init__(self, request):
         super(CacheURL, self).__init__()
         try:
-            self._data = request.data.copy()
+            self._data = copy.deepcopy(request.data)
         except AttributeError:
             self._data = {}
-        self._template_data = request.template_data.copy()
+        self._template_data = copy.deepcopy(request.template_data)
         self._prepath = request.prepath[:]
         self._postpath = request.postpath[:]
         del self._template_data["csrf_token"]
 
     def use(self, request):
         self.last_access = time.time()
-        request.data = self._data.copy()
-        request.template_data.update(self._template_data)
+        request.data = copy.deepcopy(self._data)
+        request.template_data.update(copy.deepcopy(self._template_data))
         request.prepath = self._prepath[:]
         request.postpath = self._postpath[:]