From df1aa689be097b71d9dc2ef7e6cdb875337083c6 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 20 Aug 2019 09:26:07 +0000 Subject: [PATCH] [FIX] web: race condition in export widget Looks like the race condition dates back to the introduction of "default" export fields but #32339 made it into a hard error (rather than silently not load the fields): setting / selecting the default fields waited in the exports lists to be loaded, but the exports lists are just predefined lists of fields, that's got no relation to the loaded or default fields, which are loaded (somewhat implicitly) by _onChangeCompatibleInput. As a result, if the lookup of the ir.exports was faster than fetching the model's fields, we'd execute "select the fields from the list view" before the exports widget knew anyting about the model's own fields. Because the old code iterated on the loaded fields and checked if they were to enable it would just do nothing (as it would iterate an empty object). Because the new code iterates on the defaults fields and looks them up in the records map, it gets an undefined and triggers an error. Fix by waiting on the proper RPC call. Reported-by: Andreas Stauder (@BT-astauder) closes odoo/odoo#35837 Signed-off-by: Xavier Morel (xmo) --- addons/web/static/src/js/widgets/data_export.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/addons/web/static/src/js/widgets/data_export.js b/addons/web/static/src/js/widgets/data_export.js index 975cc99e35c..964e03e4aa1 100644 --- a/addons/web/static/src/js/widgets/data_export.js +++ b/addons/web/static/src/js/widgets/data_export.js @@ -66,7 +66,12 @@ var DataExport = Dialog.extend({ this.$fieldsList = this.$('.o_fields_list'); proms.push(this._rpc({route: '/web/export/formats'}).then(doSetupExportFormats)); - proms.push(this._onChangeCompatibleInput()); + proms.push(this._onChangeCompatibleInput().then(function () { + _.each(self.defaultExportFields, function (field) { + var record = self.records[field]; + self._addField(record.id, record.string); + }); + })); proms.push(this.getParent().getActiveDomain().then(function (domain) { if (domain === undefined) { @@ -78,12 +83,7 @@ var DataExport = Dialog.extend({ } })); - proms.push(this._showExportsList().then(function () { - _.each(self.defaultExportFields, function (field) { - var record = self.records[field]; - self._addField(record.id, record.string); - }); - })); + proms.push(this._showExportsList()); // Bind sortable events after Dialog is open this.opened().then(function () {