From 897296208fe1fbb24084346009522fb01740368e Mon Sep 17 00:00:00 2001 From: Damien Bouvy Date: Thu, 4 Jan 2024 15:01:00 +0100 Subject: [PATCH] [FIX] base_automation: avoid key error when trying to return a warning Before the refactoring introduced at 0a744ac, it was possible to return a warning from a `code`-type base automation with the `action` variable: ```py if len(record.name) > 20: action = { "warning": { "title": "Name too long", "message": "The name of the record is too long", } } ``` This would trigger a visual dialog with the title and message in the client. Due to a louche `+=` operator change in the refacto, this kind of automation raises a key error on the server, as the additive part of the operator will try to access the 'warning' key in the result dict, which may not (and usually will not) exist. I assume this was done in an attempt to 'accumulate' warnings, but the warnings in questions are dict that are not really additive anyway. Better to support the *last* returned warning rather than none at all. This commit basically returns to the previous situation for onchange warnings. closes odoo/odoo#148140 Signed-off-by: Bouvy Damien (dbo) --- addons/base_automation/models/base_automation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/base_automation/models/base_automation.py b/addons/base_automation/models/base_automation.py index f22341308fd..f1cf22ee3e5 100644 --- a/addons/base_automation/models/base_automation.py +++ b/addons/base_automation/models/base_automation.py @@ -805,7 +805,7 @@ class BaseAutomation(models.Model): if 'domain' in res: result.setdefault('domain', {}).update(res['domain']) if 'warning' in res: - result['warning'] += res["warning"] + result['warning'] = res["warning"] return result return base_automation_onchange