summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2018-09-10 10:03:47 +0200
committerAaron Bohy <aab@odoo.com>2018-09-11 21:05:23 +0200
commita131373fac22bc1b7c57acd423f526bf73a0d31b (patch)
treeaf3e558f9f5b05fe9d31f2d36229088dd4c13475 /addons/web/static/src/js
parent0ff2087fb9af17ef2359b3912d424b4ece20951f (diff)
[FIX] web: wait for onchanges before saving
Rev. db9b91ff removes a use of a mutex where it could end up in a deadlock situation (and where the use of the mutex wasn't necessary). However, it caused an issue as the following scenario didn't work anymore: - in a form view with a one2many with fields A and B (required), with an onchange on A setting B, - add a row and set a value for A, - click on 'Save' directly (before the onchange RPC returns) - whereas it should wait for the onchange to return before trying to save, it tries to save directly but faces an unset required field, and displays a warning to the user. The reason is that, before saving, the FormController asks all its widgets to commit their value (through a call to commitChange). This call was, prior to db9b91ff, done in the mutex. The onchange RPC being itself done in that mutex, we thus waited for the onchange to return before calling commitChanges. After db9b91ff, since there was no longer a mutex, commitChanges was called directly, and the editable list returned a warning as one of its required field was unset. This commit ensures that commitChanges is called once all onchange RPCs are done, by waiting the mutex to be idle.
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/views/basic/basic_controller.js11
1 files changed, 8 insertions, 3 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_controller.js b/addons/web/static/src/js/views/basic/basic_controller.js
index 767a6511ce3..43d604eac0b 100644
--- a/addons/web/static/src/js/views/basic/basic_controller.js
+++ b/addons/web/static/src/js/views/basic/basic_controller.js
@@ -173,15 +173,20 @@ var BasicController = AbstractController.extend(FieldManagerMixin, {
// may have to validate them before notifying them, so we ask them to
// commit their current value before saving. This has to be done outside
// of the mutex protection of saving because commitChanges will trigger
- // changes and these are also protected. So the actual saving has to be
+ // changes and these are also protected. However, we must wait for the
+ // mutex to be idle to ensure that onchange RPCs returned before asking
+ // field widgets to commit their value (and validate it, for instance
+ // for one2many with required fields). So the actual saving has to be
// done after these changes. Also the commitChanges operation might not
// be synchronous for other reason (e.g. the x2m fields will ask the
// user if some discarding has to be made). This operation must also be
// mutex-protected as commitChanges function of x2m has to be aware of
// all final changes made to a row.
var self = this;
- return this.renderer.commitChanges(recordID || this.handle).then(function () {
- return self.mutex.exec(self._saveRecord.bind(self, recordID, options));
+ return this.mutex.getUnlockedDef().then(function () {
+ return self.renderer.commitChanges(recordID || self.handle).then(function () {
+ return self.mutex.exec(self._saveRecord.bind(self, recordID, options));
+ });
});
},
/**