Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] rename_models: add condition to check version and existence of ir_property table #395

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 33 additions & 32 deletions openupgradelib/openupgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -975,48 +975,49 @@ def rename_models(cr, model_spec):
old,
),
)
logged_query(
cr,
"""
UPDATE ir_property
SET res_id = replace(res_id, %(old_string)s, %(new_string)s)
WHERE res_id like %(old_pattern)s""",
{
"old_pattern": "%s,%%" % old,
"old_string": "%s," % old,
"new_string": "%s," % new,
},
)
# Handle properties that reference to this model
logged_query(
cr,
"SELECT id FROM ir_model_fields "
"WHERE relation = %s AND ttype = 'many2one'",
(old,),
)
field_ids = [x[0] for x in cr.fetchall()]
logged_query(
cr,
"UPDATE ir_model_fields SET relation = %s WHERE relation = %s",
(
new,
old,
),
)
if field_ids:
if version_info[0] < 18 and table_exists(cr, "ir_property"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the reason to check if ir_property exists as a table?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just denying the case if the ir_property table exists and the version is >= 18.0. because in fact if you use a database from 17.0 or earlier to migrate data to version >= 18.0, the ir_property table still exists and is just no longer used.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that even in version 18 no operations should be performed in the table even if it exists! I would say checking the version is enough because we can rely on the table existing in earlier versions.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, maybe it's redundant. i will update it in next patch

logged_query(
cr,
"""
UPDATE ir_property
SET value_reference = replace(
value_reference, %(old_string)s, %(new_string)s)
WHERE value_reference like %(old_pattern)s""",
SET res_id = replace(res_id, %(old_string)s, %(new_string)s)
WHERE res_id like %(old_pattern)s""",
{
"old_pattern": "%s,%%" % old,
"old_string": "%s," % old,
"new_string": "%s," % new,
},
)
# Handle properties that reference to this model
logged_query(
cr,
"SELECT id FROM ir_model_fields "
"WHERE relation = %s AND ttype = 'many2one'",
(old,),
)
field_ids = [x[0] for x in cr.fetchall()]
logged_query(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go outside the if.

cr,
"UPDATE ir_model_fields SET relation = %s WHERE relation = %s",
(
new,
old,
),
)
if field_ids:
logged_query(
cr,
"""
UPDATE ir_property
SET value_reference = replace(
value_reference, %(old_string)s, %(new_string)s)
WHERE value_reference like %(old_pattern)s""",
{
"old_pattern": "%s,%%" % old,
"old_string": "%s," % old,
"new_string": "%s," % new,
},
)
# Handle models that reference to this model using reference fields
cr.execute(
"""
Expand Down
Loading