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/tests/views/basic_model_tests.js | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'addons/web/static/tests/views/basic_model_tests.js') diff --git a/addons/web/static/tests/views/basic_model_tests.js b/addons/web/static/tests/views/basic_model_tests.js index 492dfd4224c..bf5261c5b6e 100644 --- a/addons/web/static/tests/views/basic_model_tests.js +++ b/addons/web/static/tests/views/basic_model_tests.js @@ -669,6 +669,42 @@ QUnit.module('Views', { model.destroy(); }); + QUnit.test('default_get returning a non requested field', function (assert) { + // 'default_get' returns a default value for the fields given in + // arguments. It should not return a value for fields that have not be + // requested. However, it happens (e.g. res.users), and the webclient + // should not crash when this situation occurs (the field should simply + // be ignored). + assert.expect(2); + + this.params.context = {}; + this.params.fieldNames = ['category']; + this.params.res_id = undefined; + this.params.type = 'record'; + + var model = createModel({ + Model: BasicModel, + data: this.data, + mockRPC: function (route, args) { + var result = this._super(route, args); + if (args.method === 'default_get') { + result.product_ids = [[6, 0, [37, 41]]]; + } + return result; + }, + }); + + model.load(this.params).then(function (resultID) { + var record = model.get(resultID); + assert.ok('category' in record.data, + "should have processed 'category'"); + assert.notOk('product_ids' in record.data, + "should have ignored 'product_ids'"); + }); + + model.destroy(); + }); + QUnit.test('can make a default_record with default relational values', function (assert) { assert.expect(7); -- cgit v1.2.3