From c685fc18c1fe4a82f48304c886647f69f4bf939b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Thu, 26 Aug 2021 15:45:42 +0000 Subject: [PATCH] [IMP] mail: prevent "already in update cycle" loop after crash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit task-2620828 closes odoo/odoo#75661 Signed-off-by: Alexandre Kühn (aku) --- addons/mail/static/src/model/model_manager.js | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/addons/mail/static/src/model/model_manager.js b/addons/mail/static/src/model/model_manager.js index 7a32c232977..751bdd50c15 100644 --- a/addons/mail/static/src/model/model_manager.js +++ b/addons/mail/static/src/model/model_manager.js @@ -815,21 +815,24 @@ export class ModelManager { if (this._isInUpdateCycle) { throw Error('Already in update cycle. You are probably trying to manually create/update/delete a record from inside a compute method, which is not supported.'); } - this._isInUpdateCycle = true; - this._notifyListenersInUpdateCycle(); - // Verify the existence of value for required fields (of non-deleted records). - for (const record of this._updatedRecords) { - if (!record.exists()) { - continue; - } - for (const required of record.constructor.__requiredFieldsList) { - if (record[required.fieldName] === undefined) { - throw Error(`Field ${required.fieldName} of ${record.localId} is required.`); + try { + this._isInUpdateCycle = true; + this._notifyListenersInUpdateCycle(); + // Verify the existence of value for required fields (of non-deleted records). + for (const record of this._updatedRecords) { + if (!record.exists()) { + continue; + } + for (const required of record.constructor.__requiredFieldsList) { + if (record[required.fieldName] === undefined) { + throw Error(`Field ${required.fieldName} of ${record.localId} is required.`); + } } } + this._updatedRecords.clear(); + } finally { + this._isInUpdateCycle = false; } - this._updatedRecords.clear(); - this._isInUpdateCycle = false; // Execution of `_created` and "on change" (after the update cycle itself). while (this._createdRecords.size > 0) { for (const record of this._createdRecords) {