Skip to content

Commit dd29b9f

Browse files
committed
[IMP] util.move_field_to_module
Rewrote function to no use a savepoint. Part-of: #276 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 8edf672 commit dd29b9f

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/util/fields.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@
2525

2626
try:
2727
from odoo import release
28-
from odoo.tools.misc import mute_logger
2928
except ImportError:
3029
from openerp import release
31-
from openerp.tools.misc import mute_logger
3230

3331
from .domains import FALSE_LEAF, TRUE_LEAF
3432

@@ -56,6 +54,7 @@ def make_index_name(table_name, column_name):
5654
explode_execute,
5755
explode_query_range,
5856
format_query,
57+
get_columns,
5958
get_value_or_en_translation,
6059
parallel_execute,
6160
pg_text2html,
@@ -455,23 +454,25 @@ def move_field_to_module(cr, model, fieldname, old_module, new_module, skip_inhe
455454
"""
456455
_validate_model(model)
457456
name = IMD_FIELD_PATTERN % (model.replace(".", "_"), fieldname)
458-
try:
459-
with savepoint(cr), mute_logger("openerp.sql_db", "odoo.sql_db"):
460-
cr.execute(
461-
"""
462-
UPDATE ir_model_data
463-
SET module = %s
464-
WHERE model = 'ir.model.fields'
465-
AND name = %s
466-
AND module = %s
467-
""",
468-
[new_module, name, old_module],
469-
)
470-
except psycopg2.IntegrityError:
471-
cr.execute(
472-
"DELETE FROM ir_model_data WHERE model = 'ir.model.fields' AND name = %s AND module = %s",
473-
[name, old_module],
474-
)
457+
columns = get_columns(cr, "ir_model_data", ignore=["id", "module"])
458+
query = format_query(
459+
cr,
460+
"""
461+
INSERT INTO ir_model_data({0}, module)
462+
SELECT {0}, %s
463+
FROM ir_model_data
464+
WHERE model = 'ir.model.fields'
465+
AND name = %s
466+
AND module = %s
467+
ON CONFLICT DO NOTHING
468+
""",
469+
columns,
470+
)
471+
cr.execute(query, [new_module, name, old_module])
472+
cr.execute(
473+
"DELETE FROM ir_model_data WHERE model = 'ir.model.fields' AND name = %s AND module = %s",
474+
[name, old_module],
475+
)
475476
# move field on inherits
476477
for inh in for_each_inherit(cr, model, skip_inherit):
477478
move_field_to_module(cr, inh.model, fieldname, old_module, new_module, skip_inherit=skip_inherit)

0 commit comments

Comments
 (0)