[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) <xmo@odoo.com>
This commit is contained in:
Xavier Morel
2019-08-20 09:26:07 +00:00
parent 9920f20e4c
commit df1aa689be
@@ -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 () {