From 034c075e7e58ad9e5a2dce34782106c0dbd1c786 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Mon, 26 Feb 2018 08:48:19 +0100 Subject: [FIX] web: default_get returning unknown field Before this rev., it crashed when trying to create records of the res.users model. This is due to commit ad1cceb. The 'default_get' of 'res.users' always returns a value for field 'groups_id', whereas the docstring of 'default_get' states that it only returns default values for fields given in arguments. Rev. ad1cceb changed a bit the way the result of 'default_get' was processed, by iterating over the values instead of over the fields in the view. So, before ad1cceb, 'groups_id' was simply ignored, and after, the BasicModel tried to process it and it crashed when it attempted to retrieve its fieldsInfo, as this field isn't in the view. This rev. restores the previous behavior. Fixes #23303 Fixes #23305 --- addons/web/static/src/js/views/basic/basic_model.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'addons/web/static/src/js/views/basic/basic_model.js') diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js index 18193a5c364..c7f61edd541 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -219,6 +219,10 @@ var BasicModel = AbstractModel.extend({ var fieldName; record._changes = record._changes || {}; + // ignore values for non requested fields (for instance, fields that are + // not in the view) + values = _.pick(values, fieldNames); + // fill default values for missing fields for (var i = 0; i < fieldNames.length; i++) { fieldName = fieldNames[i]; @@ -240,9 +244,6 @@ var BasicModel = AbstractModel.extend({ var defs = []; for (fieldName in values) { field = record.fields[fieldName]; - if (!field) { - continue; // ignore values for unknown fields - } record.data[fieldName] = null; var dp; if (field.type === 'many2one' && values[fieldName]) { -- cgit v1.2.3