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

[FIX] base: do not overwrite context when upgrading #71802

Conversation

MiquelRForgeFlow
Copy link
Contributor

@MiquelRForgeFlow MiquelRForgeFlow commented Jun 7, 2021

Just allow to pass flags to the context of _process_end method.

(the same is done in https://github.com/odoo/odoo/blob/14.0/odoo/addons/base/models/ir_model.py#L2087)

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

@robodoo
Copy link
Contributor

robodoo commented Jun 7, 2021

@C3POdoo C3POdoo added the ORM ORM, python Framework related label Jun 7, 2021
@MiquelRForgeFlow
Copy link
Contributor Author

please @rco-odoo could you check? we need this and it's very simple

@rco-odoo
Copy link
Member

Why? Can you please explain the problem you are trying to solve?

@MiquelRForgeFlow
Copy link
Contributor Author

Well, we want to pas some context info when calling the _process_end method, but this method is overwriting the context :S

@rco-odoo
Copy link
Member

Well, we want to pas some context info when calling the _process_end method, but this method is overwriting the context :S

This is what you want to do, not why you want to do it.

Besides, _process_end() is designed to be called from loading.py after upgrading some modules. By design the calling context is empty, because loading the registry is a "neutral" operation (no lang, no timezone, no current company, whatsoever).

@MiquelRForgeFlow
Copy link
Contributor Author

As to why we want to pass flags in context in this method, it's to be able to do nice hooks instead of superugly hooks. It happens that when doing _process_end(), it may try to delete some model data and we are in a project where we don't want that deletion somehow in some cases.

@rco-odoo
Copy link
Member

I really don't get it. As I wrote before, _process_end() is called from loading.py with the superuser and an empty context. If you want to prevent the deletion in some circumstances, those circumstances cannot depend on the current user or context, but can only depend on the database. That should be doable with a simple override of unlink(), isn't it?

@MiquelRForgeFlow
Copy link
Contributor Author

MiquelRForgeFlow commented Jun 17, 2021

Well, let's go with a broader explanation:

We in OpenUpgrade (v13) project (a fork which contains some core patches to avoid deleting obsolete data) added this FIX to avoid an error. But in OpenUpgrade (v14) project we decided to avoid doing a fork, and we proceed with clean monkeypatches approach. That fix was forward ported here (in a clean but a bit convoluted way), because we don't want to do ugly monkeypatches with verbatim copies of odoo methods. But we found that this patch only fixes the uninstall case, but not the upgrading case. We detected the upgrading case error in base_automation migration, that when doing _process_end() it gives the error of obsolete base.automation.lead.test model not being in the environment. I added in that PR a commit to solve that by passing a flag, but the overwriting in the context in _process_end() evades my fix.

Well, I know you have your migration process and maybe don't like our free community approach, that's why I didn't want to say it at the beginning. I hope you understand all I said, and feel free to ask anything.

@rco-odoo
Copy link
Member

Well, let's go with a broader explanation:

We in OpenUpgrade (v13) project (a fork which contains some core patches to avoid deleting obsolete data) added this FIX to avoid an error. But in OpenUpgrade (v14) project we decided to avoid doing a fork, and we proceed with clean monkeypatches approach. That fix was forward ported here (in a clean but a bit convoluted way), because we don't want to do ugly monkeypatches with verbatim copies of odoo methods. But we found that this patch only fixes the uninstall case, but not the upgrading case. We detected the upgrading case error in base_automation migration, that when doing _process_end() it gives the error of obsolete base.automation.lead.test model not being in the environment. I added in that PR a commit to solve that by passing a flag, but the overwriting in the context in _process_end() evades my fix.

Ouch! I understand how the monkeypatch works, but it looks so fragile: any fix in the original code can make it break.

We solve such cases in a different way. Our migration framework runs scripts that adapts data in plain SQL most of the time. This avoids the problem of the missing model, and is usually much more efficient. If the default process fails, we adapt the scripts to solve the problem ahead of the failure.

I will ask for other opinions before making a decision.

@rco-odoo
Copy link
Member

BTW I noticed that

  • _module_data_uninstall() extends the context here, while
  • _process_end() forces the context here

@MiquelRForgeFlow
Copy link
Contributor Author

@rco-odoo Yeah. I hope we receive your green-light soon.

@MiquelRForgeFlow
Copy link
Contributor Author

BTW I noticed that

_module_data_uninstall() extends the context [here], while
_process_end() forces the context [here]

@rco-odoo any chance this minor patch can be accepted? 🙏 I mean, I don't see why one method has to extend and the other has to force. Let's make both extend to overall "harmonize" it?

I can edit the commit message if you prefer and put something more suitable.

Just allow to pass flags to the context of _process_end method.
@MiquelRForgeFlow MiquelRForgeFlow force-pushed the 14.0-fix-base-do-not-overwrite-context-in-upgrade branch from e6b7e0c to adc9679 Compare June 12, 2023 09:47
@C3POdoo C3POdoo requested review from a team, Gorash and Julien00859 and removed request for a team June 12, 2023 10:01
@C3POdoo
Copy link
Contributor

C3POdoo commented Apr 16, 2024

Dear @MiquelRForgeFlow,

Thank you for your contribution but the version 14.0 is no longer supported.
We only support the last 3 stable versions so no longer accepts patches into this branch.

We apology if we could not look at your request in time.
If the contribution still makes sense for the upper version, please let us know and do not hesitate to recreate one for the recent versions. We will try to check it as soon as possible.

This is an automated message.

@C3POdoo C3POdoo closed this Apr 16, 2024
@MiquelRForgeFlow MiquelRForgeFlow deleted the 14.0-fix-base-do-not-overwrite-context-in-upgrade branch April 16, 2024 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ORM ORM, python Framework related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants