Skip to content

Override of migrate_module not working as expected #3285

@jcdrubay

Description

@jcdrubay

Module

openupgrade_framework

Describe the bug

This function is not honoring it's docstring.

def migrate_module(self, pkg, stage):
    """In openupgrade, also run migration scripts upon installation.
    We want to always pass in pre and post migration files and use a new
    argument in the migrate decorator (explained in the docstring)
    to decide if we want to do something if a new module is installed
    during the migration.
    We trick Odoo into running the scripts by setting the update attribute if necessary.
    """
    has_update = hasattr(pkg, "update")
    if not has_update:
        pkg.update = True
    MigrationManager.migrate_module._original_method(self, pkg, stage)
    if not has_update:
        delattr(pkg, "update")

To Reproduce

Version 15.0 (probably earlier version as 13.0 and 14.0 of Odoo has the same if statement)

Steps to reproduce the behavior:

  1. Run upgrade for a module which was renamed, the pre-migration is not executed.

Expected behavior
Run the pre-migration script.

Additional context

In https://github.com/odoo/odoo/blob/15.0/odoo/modules/migration.py#L101
The if statement of original function migrate_module is positive because the state of the module is "to install".

        if not (hasattr(pkg, 'update') or state == 'to upgrade') or state == 'to install':
            return

Suggested new code:

--- a/openupgrade_framework/odoo_patch/odoo/modules/migration.py
+++ b/openupgrade_framework/odoo_patch/odoo/modules/migration.py
@@ -14,9 +14,15 @@ def migrate_module(self, pkg, stage):
     has_update = hasattr(pkg, "update")
     if not has_update:
         pkg.update = True
+
+    to_install = pkg.state == "to install"
+    pkg.state = "to ugprade"
     MigrationManager.migrate_module._original_method(self, pkg, stage)
     if not has_update:
         delattr(pkg, "update")
+    if to_install:
+        pkg.state = "to install"
+

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions