From 6a3444e5bdbfbc22a42e3c6d354645af7bdfdc5c Mon Sep 17 00:00:00 2001 From: Ayman Adil Date: Fri, 9 Dec 2022 15:52:37 +0000 Subject: [PATCH] [FIX] convert.py: skip the creation of a `forcecreate=0` record when a reference is missing When a record is `forcecreate=0` and a reference of one of its fields is missing, the update of the corresponding module fails. In this case, we can skip the creation of this record. An example of this issue is this [record](https://github.com/odoo/enterprise/blob/6411ae071ace980834befeb8040c94b1a05c8034/documents_account/data/data.xml#L17) in `documents_account` module (enterprise) when the reference of this [field](https://github.com/odoo/enterprise/blob/6411ae071ace980834befeb8040c94b1a05c8034/documents_account/data/data.xml#L20) is missing. This can be reproduced as follows: 1. Create a DB with `documents_account` module 2. Uninstall `documents_account` module 3. Remove `documents.documents_finance_status` 4. Reinstall `documents_account` ``` Traceback (most recent call last): File "/home/ayman/src/odoo/15.0/odoo/tools/convert.py", line 680, in _tag_root f(rec) File "/home/ayman/src/odoo/15.0/odoo/tools/convert.py", line 567, in _tag_record f_val = self.id_get(f_ref) File "/home/ayman/src/odoo/15.0/odoo/tools/convert.py", line 663, in id_get res = self.model_id_get(id_str, raise_if_not_found) File "/home/ayman/src/odoo/15.0/odoo/tools/convert.py", line 669, in model_id_get return self.env['ir.model.data']._xmlid_to_res_model_res_id(id_str, raise_if_not_found=raise_if_not_found) File "/home/ayman/src/odoo/15.0/odoo/addons/base/models/ir_model.py", line 1943, in _xmlid_to_res_model_res_id return self._xmlid_lookup(xmlid)[1:3] File "", line 2, in _xmlid_lookup File "/home/ayman/src/odoo/15.0/odoo/tools/cache.py", line 90, in lookup value = d[key] = self.method(*args, **kwargs) File "/home/ayman/src/odoo/15.0/odoo/addons/base/models/ir_model.py", line 1936, in _xmlid_lookup raise ValueError('External ID not found in the system: %s' % xmlid) ValueError: External ID not found in the system: documents.documents_finance_status ``` closes odoo/odoo#107766 X-original-commit: 2e4f0667397d2d6670df50b9088fa9c23f1f9f5a Signed-off-by: Christophe Simonis --- odoo/tools/convert.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/odoo/tools/convert.py b/odoo/tools/convert.py index 17c2c7bf58c..7eeb24beba2 100644 --- a/odoo/tools/convert.py +++ b/odoo/tools/convert.py @@ -417,7 +417,10 @@ form: module.record_id""" % (xml_id,) val = self.model_id_get(f_ref) f_val = val[0] + ',' + str(val[1]) else: - f_val = self.id_get(f_ref) + f_val = self.id_get(f_ref, raise_if_not_found=nodeattr2bool(rec, 'forcecreate', True)) + if not f_val: + _logger.warning("Skipping creation of %r because %s=%r could not be resolved", xid, f_name, f_ref) + return None else: f_val = _eval_xml(self, field, env) if f_name in model._fields: