changeset 97651de5ca7a in tryton:5.2
details: https://hg.tryton.org/tryton?cmd=changeset;node=97651de5ca7a
description:
        Prevent modification of cache RPC answers

        The cached value should never be changed after being stored by the 
setter or
        by a getter. So we make a copy of the value before storing it and return
        another copy when returned.

        issue8387
        review269601002
        (grafted from 5ec90db3ed7a237957d23461c03a49b69a34130a)
diffstat:

 tryton/jsonrpc.py |  5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diffs (28 lines):

diff -r 46a11598ac95 -r 97651de5ca7a tryton/jsonrpc.py
--- a/tryton/jsonrpc.py Mon Jun 10 23:14:36 2019 +0200
+++ b/tryton/jsonrpc.py Wed Jun 12 19:04:42 2019 +0200
@@ -1,5 +1,6 @@
 # This file is part of Tryton.  The COPYRIGHT file at the top level of
 # this repository contains the full copyright notices and license terms.
+import copy
 import xmlrpc.client
 import json
 import ssl
@@ -402,7 +403,7 @@
             expire = datetime.timedelta(seconds=expire)
         if isinstance(expire, datetime.timedelta):
             expire = datetime.datetime.now() + expire
-        self.store[prefix][key] = (expire, value)
+        self.store[prefix][key] = (expire, copy.deepcopy(value))
 
     def get(self, prefix, key):
         now = datetime.datetime.now()
@@ -414,7 +415,7 @@
             self.store.pop(key)
             raise KeyError
         logger.info('(cached) %s %s', prefix, key)
-        return value
+        return copy.deepcopy(value)
 
     def clear(self, prefix=None):
         if prefix:

Reply via email to