Skip to content

Commit 86d814b

Browse files
committed
[FIX] util.fields: error when table of model base_import.mapping doesn't exist
In 1d9e20e, a new feature was implemented to consider the model `base_import.mapping` when removing fields. However, it was not considering if the table doesn't exist, which could occur when migrating from a version <= 11.0. That causes the following error in such cases: relation "base_import_mapping" does not exist This commit fixes the above issue by ensuring the table actually exists before accessing it. closes #107 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent a05df66 commit 86d814b

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/util/records.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -495,18 +495,21 @@ def _remove_import_export_paths(cr, model, field=None):
495495
else:
496496
export_q += " WHERE el.name IS NOT NULL"
497497

498-
import_q = """
499-
SELECT id,
500-
res_model,
501-
STRING_TO_ARRAY(field_name, '/')
502-
FROM base_import_mapping
503-
"""
504-
if field:
505-
import_q = cr.mogrify(import_q + " WHERE field_name ~ %s ", [r"\y{}\y".format(field)]).decode()
506-
else:
507-
import_q += " WHERE field_name IS NOT NULL "
498+
impex_data = [(export_q, "ir_exports_line")]
499+
if table_exists(cr, "base_import_mapping"):
500+
import_q = """
501+
SELECT id,
502+
res_model,
503+
STRING_TO_ARRAY(field_name, '/')
504+
FROM base_import_mapping
505+
"""
506+
if field:
507+
import_q = cr.mogrify(import_q + " WHERE field_name ~ %s ", [r"\y{}\y".format(field)]).decode()
508+
else:
509+
import_q += " WHERE field_name IS NOT NULL "
510+
impex_data.append((import_q, "base_import_mapping"))
508511

509-
for query, impex_model in [(export_q, "ir.exports.line"), (import_q, "base_import.mapping")]:
512+
for query, impex_model in impex_data:
510513
cr.execute(query)
511514
to_rem = [
512515
path_id

0 commit comments

Comments
 (0)