Skip to content

Commit

Permalink
[FIX] util.fields: error when table of model base_import.mapping does…
Browse files Browse the repository at this point in the history
…n'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) <chs@odoo.com>
  • Loading branch information
luisg123v committed Jul 6, 2024
1 parent a05df66 commit 86d814b
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/util/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,18 +495,21 @@ def _remove_import_export_paths(cr, model, field=None):
else:
export_q += " WHERE el.name IS NOT NULL"

import_q = """
SELECT id,
res_model,
STRING_TO_ARRAY(field_name, '/')
FROM base_import_mapping
"""
if field:
import_q = cr.mogrify(import_q + " WHERE field_name ~ %s ", [r"\y{}\y".format(field)]).decode()
else:
import_q += " WHERE field_name IS NOT NULL "
impex_data = [(export_q, "ir_exports_line")]
if table_exists(cr, "base_import_mapping"):
import_q = """
SELECT id,
res_model,
STRING_TO_ARRAY(field_name, '/')
FROM base_import_mapping
"""
if field:
import_q = cr.mogrify(import_q + " WHERE field_name ~ %s ", [r"\y{}\y".format(field)]).decode()
else:
import_q += " WHERE field_name IS NOT NULL "
impex_data.append((import_q, "base_import_mapping"))

for query, impex_model in [(export_q, "ir.exports.line"), (import_q, "base_import.mapping")]:
for query, impex_model in impex_data:
cr.execute(query)
to_rem = [
path_id
Expand Down

0 comments on commit 86d814b

Please sign in to comment.