Skip to content

[IMP] Prevent duplicate module issues when renaming modules.#434

Open
ddejong-therp wants to merge 1 commit intoOCA:masterfrom
Therp:better-module-renames
Open

[IMP] Prevent duplicate module issues when renaming modules.#434
ddejong-therp wants to merge 1 commit intoOCA:masterfrom
Therp:better-module-renames

Conversation

@ddejong-therp
Copy link
Contributor

@ddejong-therp ddejong-therp commented Jan 26, 2026

This PR changes the update_module_names method, to also remove a module when its state is "uninstalled".

Sometimes a module from the 'rename' list of apriory.py, gets renamed to a given name, but a record with that name already exists in the ir_module_module table, with its state being "unistalled".
So that will cause duplicate key voilation error to happen.

If the module was previously uninstalled, but it needs to be installed because of a rename, why not allow that by removing the records related to the target/uninstalled module?

EDIT: Here someone else experienced the same thing: OCA/OpenUpgrade#4673

@pedrobaeza
Copy link
Member

Wasn't the argument merge_modules=True handling that?

@ddejong-therp
Copy link
Contributor Author

Well, merge_modules=True also handles merging modules when the target module is installed.
And this is about when the target module is only uninstalled.

@pedrobaeza
Copy link
Member

But you have to use that argument when the module already exists, so I don't get the sense of the patch.

@ddejong-therp
Copy link
Contributor Author

The thing is, the method is being used in migration script of the base module, which uses apriori.py from the OpenUpgrade repo to determine for which modules that flag needs to be given as True or False.
So I'm guessing that what you mean is that the module in question should be listed in the merged_modules dictionary.

However, I think it is not always as simple as that. Think of this scenario:
Maybe someone once installed, and later uninstalled, a custom module. Now, when migrating your database with OpenUpgrade, a new OCA module exists with the same name in a later version of Odoo.
Now you get a constraint violation, because the ir_module_module record already exist, even though there is nothing really that needs to stop you from renaming a module to the relevant name.

@StefanRijnhart
Copy link
Member

Doesn't database_cleanup solve this when run (at some point) before the migration? It's always a good idea to do so.

@ddejong-therp
Copy link
Contributor Author

Well I guess it would, but why have people rely on such a tool, if it doesn't need to happen in the first place?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants