OpenUpgrade icon indicating copy to clipboard operation
OpenUpgrade copied to clipboard

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

Open pedrobaeza opened this issue 1 year ago • 15 comments

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 avatar Jul 06 '24 12:07 pedrobaeza

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

pedrobaeza avatar Jul 06 '24 12:07 pedrobaeza

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.

legalsylvain avatar Jul 06 '24 21:07 legalsylvain

isn't this a job for database_cleanup?

hbrunn avatar Jul 08 '24 08:07 hbrunn

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 ?

legalsylvain avatar Jul 08 '24 13:07 legalsylvain

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.

pedrobaeza avatar Jul 08 '24 14:07 pedrobaeza

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

StefanRijnhart avatar Jul 08 '24 15:07 StefanRijnhart

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

pedrobaeza avatar Jul 08 '24 15:07 pedrobaeza

What version are we talking about?

StefanRijnhart avatar Jul 08 '24 16:07 StefanRijnhart

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

pedrobaeza avatar Jul 08 '24 16:07 pedrobaeza

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.

StefanRijnhart avatar Jul 08 '24 16:07 StefanRijnhart

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 avatar Aug 13 '24 13:08 pedrobaeza

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 avatar Aug 13 '24 14:08 pedrobaeza

@pedrobaeza Good find!

StefanRijnhart avatar Aug 14 '24 06:08 StefanRijnhart

the condition can go into the domain too, right?

hbrunn avatar Aug 14 '24 08:08 hbrunn

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.

pedrobaeza avatar Aug 14 '24 08:08 pedrobaeza