From 2a5488619da22cfd901963dd141e722b195e82ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Ku=CC=88hn?= Date: Sun, 14 Jan 2018 21:34:13 +0100 Subject: [FIX] web: disable {bin_size: true} on binary fields Revision on 41fe7f9d1113d026b226b136b4477aaaf9f1f638 This commit intended to reduce the network load when reading records with binary fields. This was made possible by enforcing the contextual key `bin_size` to be set for records with binary fields. However, it is causing some issues (see #22222, #22231) which are: - write with bin_size:true generates a traceback - read/search_read with bin_size:true breaks some images on some views (e.g. base.view_partner_form) Since the problems outweight the gain of these changes, we revert them. --- addons/web/static/src/js/views/basic/basic_model.js | 9 +-------- 1 file changed, 1 insertion(+), 8 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 a6979776c99..d7fbee2b30d 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1854,7 +1854,7 @@ var BasicModel = AbstractModel.extend({ model: record.model, method: 'read', args: [[record.res_id], fieldNames], - context: record.getContext(), + context: _.extend({}, record.getContext(), {bin_size: true}), }) .then(function (result) { if (result.length === 0) { @@ -3094,13 +3094,6 @@ var BasicModel = AbstractModel.extend({ // datapoint context is extended by fields widgets var context = _.extend({}, params.context); - if (params.fieldsInfo && params.viewType) { - _.each(params.fieldsInfo[params.viewType], function (field) { - if (field.context) { - _.extend(context, field.context); - } - }); - } var dataPoint = { _cache: type === 'list' ? {} : undefined, -- cgit v1.2.3 From 290e247e823731ddd2a064a579677adcad1eccdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Ku=CC=88hn?= Date: Wed, 17 Jan 2018 10:27:09 +0100 Subject: [FIX] web: remove dead code Cleaning dead code from these commits that have been reverted: 41fe7f9d1113d026b226b136b4477aaaf9f1f638#diff-54fd886cc58f994ad518ee72df4d3edeR50 2a5488619da22cfd901963dd141e722b195e82ab#diff-f96b339a9374f74489f1f98755e9787bL9253 41fe7f9d1113d026b226b136b4477aaaf9f1f638#diff-86d6d41b5bb7499bf055258d05549d59R3111 With these final changes, we hope to stop the many issues that have occured with binary fields, from these commits: 255e8ca3d92e3a77d7c2a145677623518bc2f978 7813a8e714f268983b0be88827ae1c8ad887e6c7 41fe7f9d1113d026b226b136b4477aaaf9f1f638 2a5488619da22cfd901963dd141e722b195e82ab What remains is the format of binary fields in list views without widgets, which shows the bin_size instead of the base64 string representation... ... Rest assured, the computation is in JS, so there are no 'bin_size' shenaningans! --- addons/web/static/src/js/views/basic/basic_model.js | 5 +---- 1 file changed, 1 insertion(+), 4 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 d7fbee2b30d..1c25d029cfd 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -3092,16 +3092,13 @@ var BasicModel = AbstractModel.extend({ id: {type: 'integer'}, }, params.fields); - // datapoint context is extended by fields widgets - var context = _.extend({}, params.context); - var dataPoint = { _cache: type === 'list' ? {} : undefined, _changes: null, _domains: {}, _rawChanges: {}, aggregateValues: params.aggregateValues || {}, - context: context, + context: params.context, count: params.count || res_ids.length, data: data, domain: params.domain || [], -- cgit v1.2.3 From ca2060048ef7d0933b3edfd2d6a15a48bfe6373d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Wed, 17 Jan 2018 12:11:39 +0100 Subject: [FIX] web: fix issue with multiple pages and relational fields When fetching x2manys in a x2many, the basic model did not properly sort the internal data structure before fetching the data. This is usually not an issue, except when we have an order which is different from the order of the res_ids. In that case, it can cause crash in some conditions, because the results from the fetchx2manybatched were applied to the wrong datapoint. To reproduce this issue, some specific conditions needs to be met. I think that it is easier to refer to the test, instead of trying to explain that. In this commit, we properly sort the data at the correct place. Note that this probably solves a bunch of other related issues, caused by the fact that the internal structure was corrupted. --- addons/web/static/src/js/views/basic/basic_model.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (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 1c25d029cfd..cf7effb5691 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -2374,7 +2374,7 @@ var BasicModel = AbstractModel.extend({ }); record.data[fieldName] = list.id; if (!fieldInfo.__no_fetch) { - var def = self._readUngroupedList(list).then(function (list) { + var def = self._readUngroupedList(list).then(function () { return $.when( self._fetchX2ManysBatched(list), self._fetchReferencesBatched(list) @@ -2403,6 +2403,7 @@ var BasicModel = AbstractModel.extend({ var fields = view ? view.fields : fieldInfo.relatedFields; var viewType = view ? view.type : fieldInfo.viewType; list = this._applyX2ManyOperations(list); + this._sortList(list); var x2mRecords = []; // step 1: collect ids -- cgit v1.2.3 From 1bb6887bb69a121603569dd162ee7cb4304e9f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Thu, 18 Jan 2018 11:53:58 +0100 Subject: [FIX] web: fix crash when creating record with too many default values When creating a record with many default values, it could happen that the number of ids returned by the default get (or onchange) exceeds the limit for the form view. For example, we can see the issue in the expenses list view. We can increase the limit in the pager, to a value higher than 40. Then, clicking on select all, then on 'Submit to manager' in the action menu will result in a traceback. The Submit to manager action will trigger a new action with a context key 'active_ids' with a large number of ids. After that, the web client will execute the server actions, which will return a new action with a context key 'default_expense_line_ids' with a bunch of ids. Then, it will attempt to create a form view. This will call the makeDefaultRecord method in the basic model. This method will generate the commands for the one2many, for all ids, but will only load the 40 first sub records. After, it will attempt to apply the onchanges, with some code that assumes that all operations of type 'ADD' correspond to a local datapoint. In this commit, we fix the code to properly work with operations of type ADD with a res_id, but with no id. In that case, we simply generate a command 'LINK_TO', since the value has not been changed. opw 804370 --- addons/web/static/src/js/views/basic/basic_model.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (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 cf7effb5691..5296c6db7d5 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -2641,7 +2641,7 @@ var BasicModel = AbstractModel.extend({ var relRecordAdded = []; var relRecordUpdated = []; _.each(list._changes, function (change) { - if (change.operation === 'ADD') { + if (change.operation === 'ADD' && change.id) { relRecordAdded.push(self.localData[change.id]); } else if (change.operation === 'UPDATE' && !self.isNew(change.id)) { // ignore new records that would have been updated @@ -2700,6 +2700,10 @@ var BasicModel = AbstractModel.extend({ } else if (_.contains(addedIds, list.res_ids[i])) { // this is a new id (maybe existing in DB, but new in JS) relRecord = _.findWhere(relRecordAdded, {res_id: list.res_ids[i]}); + if (!relRecord) { + commands[fieldName].push(x2ManyCommands.link_to(list.res_ids[i])); + continue; + } changes = this._generateChanges(relRecord, options); if (changes.id) { // the subrecord already exists in db -- cgit v1.2.3