Skip to content

[13.0][FIX] base: Avoid possible issues with missing categories#2380

Merged
pedrobaeza merged 1 commit intoOCA:13.0from
ForgeFlow:13.0-fix-mig-base-categories
Aug 4, 2020
Merged

[13.0][FIX] base: Avoid possible issues with missing categories#2380
pedrobaeza merged 1 commit intoOCA:13.0from
ForgeFlow:13.0-fix-mig-base-categories

Conversation

@MiquelRForgeFlow
Copy link
Contributor

Some databases may have missing a category for some reason. Just in case, assure the old category exists to avoid errors in cases of missing a category.

--
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

@pedrobaeza
Copy link
Member

I don't get the change. Isn't the same?

@pedrobaeza
Copy link
Member

If not, reorder the code for clarity

@MiquelRForgeFlow
Copy link
Contributor Author

I could have done this:

for old_xmlid, new_xmlid in xmlid_renames_ir_module_category:
        module, name = new_xmlid.split('.')
        sql = "SELECT res_id FROM ir_model_data WHERE module=%s AND name=%s"
        env.cr.execute(sql, (module, name))
        new_row = env.cr.fetchone()
        if new_row:
            module, name = old_xmlid.split('.')
            env.cr.execute(sql, (module, name))
            old_row = env.cr.fetchone()
            if old_row:
                openupgrade_merge_records.merge_records(
                    env, "ir.module.category", [old_row[0]], new_row[0],
                    method="sql", model_table="ir_module_category")
        else:
+            module, name = old_xmlid.split('.')
+            env.cr.execute(sql, (module, name))
+            old_row = env.cr.fetchone()
+            if old_row:
+               openupgrade.rename_xmlids(env.cr, [(old_xmlid, new_xmlid)])
-            openupgrade.rename_xmlids(env.cr, [(old_xmlid, new_xmlid)])

that shows clearly the change, but then I reordered it to avoid repeating:

           module, name = old_xmlid.split('.')
           env.cr.execute(sql, (module, name))
           old_row = env.cr.fetchone()
           if old_row:

@pedrobaeza pedrobaeza merged commit ace5606 into OCA:13.0 Aug 4, 2020
@pedrobaeza pedrobaeza deleted the 13.0-fix-mig-base-categories branch August 4, 2020 16:27
Copy link

@AaronHForgeFlow AaronHForgeFlow left a comment

Choose a reason for hiding this comment

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

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants