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] openupgrade_framework: Do remove the ir.model.fields entries #4499

Open
pedrobaeza opened this issue Jul 6, 2024 · 15 comments
Open

[IMP] openupgrade_framework: Do remove the ir.model.fields entries #4499

pedrobaeza opened this issue Jul 6, 2024 · 15 comments
Assignees

Comments

@pedrobaeza
Copy link
Member

Several times reviewing migrated databases, to not remove the ir.model.fields entries has confused me a lot for some "missing field" errors. I agree that we should preserved the SQL columns, but I'm feeling lately that preserving also these entries only brings confusion, so I think we should remove the patch to prevent the removal on this one.

@pedrobaeza
Copy link
Member Author

What do you think @StefanRijnhart @hbrunn @MiquelRForgeFlow @legalsylvain ?

@legalsylvain
Copy link
Contributor

I have not a clear point of view on your topic. I have to begin some migrations in the summer. I'll can think about it then.

@hbrunn
Copy link
Member

hbrunn commented Jul 8, 2024

isn't this a job for database_cleanup?

@legalsylvain
Copy link
Contributor

isn't this a job for database_cleanup?

well the job of database_cleanup is to clean database that can have inconsistent things over the time.
In an openupgrade context, openupgrade keeps obsolete data (legacy_openupgrade_...) columns .
So database_cleanup allow to drop the data, and free space.

But it makes senses to conserve column, for safety reasons, and for possible reuses. The question of @pedrobaeza is : does it make sense to keeep ir.model.fields entries ? A the first sight, my answer is "no". But I need to dig deeper into the subject.

What do you think ?

@pedrobaeza
Copy link
Member Author

Yes, that's it. Although it's true that database_cleanup can also handle these ir.model.fields cleanup, having to install the module + execute the cleanup doesn't make too much sense for something that is not adding value to the OpenUpgrade preservation rule. A different story is the DB columns, which is already noted by both that should be preserved for any data recovery, extra installed modules, etc.

@StefanRijnhart
Copy link
Member

StefanRijnhart commented Jul 8, 2024

Where do we exactly override and prevent the removal of the ir.model.fields entries?

@pedrobaeza
Copy link
Member Author

Indeed I can't find such patch, but it's happening. Maybe a side effect?

@StefanRijnhart
Copy link
Member

What version are we talking about?

@pedrobaeza
Copy link
Member Author

It was 16.0, but let me retest and tell you back, as I may find an incorrect path in my procedure.

@StefanRijnhart
Copy link
Member

I would expect the ir.model.fields removal to be triggered from ir.model.data's _process_end. We have a patch there, but only to suppress some logging. Maybe the problem becomes clear if you check the logging that is emitted without this patch. Alternatively, if the migration crashes right before this point unnoticed, your database will be largely consistent except for the remaining database entries.

@pedrobaeza
Copy link
Member Author

pedrobaeza commented Aug 13, 2024

On a migration from 15 to 16, installing on the 16 migrated database the module database_cleanup, I end up with these fields to purge:

image

account_analytic_id indeed disappears in this version, but it remains in this specific database.

Creating a 15 database from scratch and migrating with OpenUpgrade, the fields entries are removed, so the process is working well.

Digging a bit more, I have found the problem:

image

There's a remaining XML-ID, which prevents it to be removed, coming from Odoo 12, where the nomenclature was changed for having a double underscore separator instead of one for avoiding problems with duplicated XML-IDs from different fields (example: field id of sale.order.type with field type_id of model sale.order - previously both had as XML-ID field_sale_order_type_id -). I think we didn't do this XML-ID renaming in OpenUpgrade, so that's the reason why now we have the problem when these fields disappear.

I will check:

  1. If we can fix this although it's a very old version. Better to have it correct in any moment.
  2. Create a script for cleaning existing databases.

cc @chienandalu

@pedrobaeza
Copy link
Member Author

This serves for cleaning old XML-ID entries:

env["ir.model.data"].search([("model", "=", "ir.model.fields")]).filtered(lambda x: "__" not in x.name).unlink()

@pedrobaeza pedrobaeza self-assigned this Aug 13, 2024
@StefanRijnhart
Copy link
Member

@pedrobaeza Good find!

@hbrunn
Copy link
Member

hbrunn commented Aug 14, 2024

the condition can go into the domain too, right?

@pedrobaeza
Copy link
Member Author

I tried that with ("name", "not like", "%__%"), but it didn't work, probably because problems with special characters in the conversion to SQL query. That's why I didn't invest much time, as at the end, this is a one time run and it doesn't take too much time to process it.

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

No branches or pull requests

4 participants