copy value before store it

This commit is contained in:
Emmanuel Garette 2019-12-02 10:42:17 +01:00
parent cdcb155acc
commit 9cc4518087

View file

@ -90,7 +90,8 @@ class Values(object):
check_error=False)
if isinstance(value, list):
# return a copy, so value cannot be modified
return value.copy()
from copy import copy
value = copy(value)
# and return it
return value
@ -177,12 +178,8 @@ class Values(object):
return value
# now try to get default value:
value = option_bag.option.impl_getdefault()
# - if option is a submulti, return a list a list
# - if option is a multi, return a list
# - default value
value = self.calc_value(option_bag, value)
value = self.calc_value(option_bag,
option_bag.option.impl_getdefault())
if option_bag.option.impl_is_multi() and option_bag.index is not None and isinstance(value, (list, tuple)):
# if index, must return good value for this index
if len(value) > option_bag.index:
@ -190,7 +187,8 @@ class Values(object):
else:
# no value for this index, retrieve default multi value
# default_multi is already a list for submulti
value = self.calc_value(option_bag, option_bag.option.impl_getdefault_multi())
value = self.calc_value(option_bag,
option_bag.option.impl_getdefault_multi())
return value
def calculate_reset_cache(self, option_bag, value):
@ -285,6 +283,9 @@ class Values(object):
self.setvalue_validation(value,
option_bag)
if isinstance(value, list):
# copy
value = value.copy()
self._setvalue(option_bag,
value,
owner,
@ -334,9 +335,6 @@ class Values(object):
owner,
commit=True):
option_bag.config_bag.context.cfgimpl_reset_cache(option_bag)
if isinstance(value, list):
# copy
value = value.copy()
self._p_.setvalue(option_bag.path,
value,
owner,