Do not allow to mutate dict value

A copy of the value is always returned so if it is modified it does not modify
the internal value of the record.
So to update Dict value, a new dictionary must be set on the field.

Closes #13374
This commit is contained in:
Cédric Krier committed 2024-06-30 01:49:42 +02:00
1 parent 8b3d5e603b
commit bfdd8924a3
4 files changed
+7 -6

No files matched your search

+3 -4
View File
@@ -2906,12 +2906,11 @@
Sao.field.Dict._super.set.call(this, record, value);
},
get: function(record) {
return (Sao.field.Dict._super.get.call(this, record) ||
this._default);
return jQuery.extend(
{}, Sao.field.Dict._super.get.call(this, record));
},
get_client: function(record) {
return (Sao.field.Dict._super.get_client.call(this, record) ||
this._default);
return Sao.field.Dict._super.get_client.call(this, record);
},
validation_domains: function(record, pre_validate) {
return this.get_domains(record, pre_validate)[0];
+1
View File
@@ -5056,6 +5056,7 @@ function eval_pyson(value){
for (const key of new_names) {
value[key] = null;
}
this.field.set_client(this.record, value);
this._display().then(() => {
this.fields[new_names[0]].input.focus();
});
@@ -1178,10 +1178,10 @@ class DictField(Field):
self.keys = {}
def get(self, record):
return super(DictField, self).get(record) or self._default
return (super().get(record) or self._default).copy()
def get_client(self, record):
return super(DictField, self).get_client(record) or self._default
return super().get_client(record)
def validation_domains(self, record, pre_validate=None):
screen_domain, attr_domain = self.domains_get(record, pre_validate)
@@ -513,6 +513,7 @@ class DictWidget(Widget):
self.send_modified()
value = self.field.get_client(self.record)
value.update({k: None for k in new_keys})
self.field.set_client(self.record, value)
self.display()
# Use idle add because it can be called from the callback