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

[RFC] Full refactor of the design of the project OpenUpgrade #2440

Closed
4 of 6 tasks
legalsylvain opened this issue Nov 3, 2020 · 49 comments
Closed
4 of 6 tasks

[RFC] Full refactor of the design of the project OpenUpgrade #2440

legalsylvain opened this issue Nov 3, 2020 · 49 comments

Comments

@legalsylvain
Copy link
Contributor

legalsylvain commented Nov 3, 2020

As talked with @pedrobaeza here, it seems that the current design of the OpenUpgrade project has some limitation :

  • forces us to maintain a big repository
  • do manual upstream updates
  • a project that is not very easy to discover and maintain. the "openupgrade" code is mixed and diluted in the Odoo code
  • we can not use OCA convention (as pre-commit stuff) for the openupgrade_records module
  • not easy to read history because openupgrade commits are mixted with official commit. The result is that fabien is in the top contributors of this repository, that is funny, but not true.

I so had the idea, and it seems @pedrobaeza also ;-) to move out the specific things of openupgrade in a new repository, to have the possilibity to use odoo code + an extra repository.

After ~20hours of work, my PoC seems to work. (still wip). I decided to work on the 14.0 revision, as it seems that no work has been started.

Here is the current code : https://github.com/legalsylvain/openupgrade-framework/tree/14.0-upgrade-pocalypse (yes, I followed the Odoo SA convention, suffixing the name of the branch with -pocalypse)

Current design proposed.

openupgrade_records

module that makes the same thing as before, calling another instance and producing migration_analysis.txt. main changes :

openupgrade_framework

a new module that contains all the patch made in Odoo. Using monkey patch. (simple exemple :
to avoid raising an error if view are broken : here.). Main changes :

  • creating the same file tree as Odoo code. so it is quite easy to use meld to analyze all the differences.
  • recovering openupgrade folder with two files openupgrade_loading.py and openupgrade_log.py. (apply OCA convention (pre-commit & co).
  • removed all the doc. (I think it should be located in another place). See original files.
  • same kind of patch has been applied for some modules, keeping also file tree. (like pre_init function disabled in V13 here and in V14 here)

This specific module should not be installed, but added in the odoo.cfg file like this server_wide_modules = openupgrade_framework. So all the monkey patches are correctly and early applied.

openupgrade_scripts

contains all the script. (for the time being, only the openupgrade_analysis.txt of a couple of modules)

Total:

  • openupgrade-framework V4 repository : 1,9 MO.
  • openupgrade V13 repository : 3 GO. (with git history).

State of the work:

  • Proof of concept
  • talk with @OCA/openupgrade-maintainers to know if they are agree with such changes for example, here.
  • make openupgrade_records working, renamed into upgrade_analysis : OK. PR to review here.
  • migrate patches from V13 to V14 : yes, still WIP, and some code has been disabled. (example here)

TODO

  • finish the work and review it
  • move the repository under @OCA umbrella. create an empty branch 14.0 with classical CI.

So, @pedrobaeza, @yajo : is this what you had in mind ?
@StefanRijnhart : what do you think regarding that move ?

thank you for your attention

@StefanRijnhart
Copy link
Member

Thanks, I like it!

@legalsylvain
Copy link
Contributor Author

thanks for your answer !

I have a design question : there are two kind of patches in OpenUpgrade.

  • some patches are for openupgrade_records module. (for exemple : this patch)

  • other patches are only for a regular "upgrade" process, to avoid errors. For example : this patch.

For the time being, all the patch are in the same module openupgrade_framework. and so this module should be in server_wide_modules for
A) generating analysis files via openupgrade_records
B) doing an upgrade.
I wonder it should be relevant to split the odoo_patch folder in two folders : one in openupgrade_records module, and odoo will be patched only for the generation of the records. keeping another folder in openupgrade_framework for the upgrade process.

I think that it could reduce the quantity of patches in the upgrade process, and so limit the possibility or errors. for exemple, I don't think that such patch in V13 and so in V14 has nothing to do in an upgrade process IMHO.

My question : do you think it's relevant to split into 2 folders of patches ? If yes could you help me to define which patch goes in witch repository ? Do you think some patches are required for both (upgrade process AND openugprade_records)

Note : it can be done later in a second time, if we face troubles with the current approach.

@StefanRijnhart
Copy link
Member

StefanRijnhart commented Nov 3, 2020

Yes, I think it would be useful to split up the patches, but then again, the patches might conflict with one another (i.e both purposes requiring to overwrite the same method).

Let's see: the core of the openupgrade_records override revolves around the upg_registry that is passed everywhere in loading.py ( https://github.com/OCA/OpenUpgrade/blame/13.0/odoo/modules/loading.py#L125), which is also involved in the runtime migration process. But we can probably work around changing the method signatures, by simply patching this structure as an attribute of threading.currentThread().

And it looks like we can move this bit https://github.com/OCA/OpenUpgrade/blame/13.0/odoo/modules/loading.py#L215-L223 to a monkey patch of registry.setup_models which is called in the line above.

There's the logging of the xml records tagged onto this method: https://github.com/OCA/OpenUpgrade/blob/13.0/odoo/tools/convert.py#L255

And that's probably it for openupgrade_records. Methods like https://github.com/OCA/OpenUpgrade/blob/13.0/odoo/openupgrade/openupgrade_log.py#L9 and a couple from https://github.com/OCA/OpenUpgrade/blob/13.0/odoo/openupgrade/openupgrade_loading.py can be moved to that module when it's hosted separately.

@legalsylvain
Copy link
Contributor Author

the patches might conflict with one another

Well, Thinking back on it, I think it's not a blocking point. If we make two odoo_patch folders it will never be executed together.

  • we will use openupgrade_records, installing this module, to generate analysis script with the patches of this module only
  • we will run migration process with the patches of the module openupgrade_framework only. (not via installation, but loaded with server_wide_modules)

So if a method is overloaded two times with similar or different patches, it's not a problem. (no conflicts)

Pros

  • less patches when running migration process
  • it will be easier to debug, when maintaining openupgrade_records and openupgrade_framework separately. (with distinct tests)
  • patches can evolve separately, and maybe some simplification can be done.
  • in the futur, maybe the people working on that two modules will not be the same. openupgrade_records is a very standalone module that has to be maintained by a few people. Whereas openupgrade_framework is used by all the people executing a migration. Some improvements could be introduced (I think on performance points, or maybe try to fix limitation like end-migration scripts of already migrated modules are not executed after resuming a failing migration #1879)

Cons

  • a little more code, if patches concern same method.
  • it will not be possible to upgrade a database with openupgrade_records installed, but it's a very theoritical problem, and I think we can live with it.

Even more, with that new approach, the port of the patches will be done in two separate times. When we want to port this repository to V15, we will first :

  • migrate the openupgrade_records. (patches lot number 1). (BTW, we could add tests that are currently not present,... or I didn't found them).
  • then, migrate openupgrade_script, populated with the execution of the module openupgrade_records.
  • then, migrate openupgrade_framework (patches lot number 2) to developp then run migration scripts.

Regarding CI, we can exclude both incompatible modules openupgrade_records and openupgrade_framework with travis.

@legalsylvain
Copy link
Contributor Author

I'll stop work on that PoC during a couple of days. In the meantime : Is it possible to have the point of view of other @OCA/openupgrade-maintainers ? mainly on that two points :

  • are you agree with this proposal ? do you see corner cases when this new approach will not work ?
  • if you're agree, when we do begin to switch to the new design ? I propose to switch to V14. But in practice, this means
  1. do not create a V14 branch on this current OCA/OpenUpgrade repository (based on a fork of Odoo/odoo V14)
  2. create a little V14 branch, with only a readme to mention the new repository.
  3. set grap/openupgrade-framework under OCA umbrella and maybe rename it, if you don't like the current name. I don't have a clear point of view regarding that topic. Possible option openupgrade-framework as rest-framework, openupgrade-tools as maintainer-tools, other proposals ?

Other question : @sbidoul : do you have a "pypi" point of view ? ;-)

@StefanRijnhart
Copy link
Member

StefanRijnhart commented Nov 4, 2020

Can we perhaps keep on working under oca/openupgrade, but with a radically different branch layout from 14.0 on as you describe? And I would propose openupgrade-analysis to host a renamed openupgrade_records with its own patches as layed out above.

--edit-- Oh I see scripts are separated from the framework. In that case, it makes sense to move to openupgrade-framework, openupgrade-scripts and openupgrade-analysis

@hbrunn
Copy link
Member

hbrunn commented Nov 4, 2020

I think that's a great initiative, thanks!

@pedrobaeza
Copy link
Member

pedrobaeza commented Nov 4, 2020

14.0 branch in OCA/OpenUpgrade will have the new layout, with 4 folders:

  • analysis folder with openupgrade_records module inside.
  • framework folder with openupgrade_framework (or just openupgrade) module inside.
  • scripts or migration_scripts folder, with a folder with each addon and their migrations folder structure.
  • doc folder, with new instructions on how to make it work (conf with server-wide, upgrade-paths and so on), and the migration coverage.

But I totally agree with this approach and excited to have it. Thanks for catching what I had in my mind since a long and make it real.

EDIT: @StefanRijnhart has finally said that separated, but I still think that better together.

@legalsylvain
Copy link
Contributor Author

intermediate proposal :

1) openupgrade_analysis :

Pro :

  • more visible in a popular repository,
  • available on oca appstore.
  • In fact, it can be executed for all modules, (OCA modules, custom modules, not only the odoo ones), including for "minor" upgrade. (I mean, if a developper decides in V14, to refactor fully a module, he could install the old version V14.X on a instance, and the new version V14.Y on another instance, and run the analysis to see all the differences).
    but if executed for odoo modules, of course the openupgrade_script should be available to write into it, but it's not a big deal, I think and can be documented.

2) openupgrade_framework and openupgrade_script

maybe merged into a single one module. (I don't see user case when developper want to have one module without the other.
Regarding the repo, I don't have a clear point of view, but keeping the same repo generates maybe extra problems :

  • regarding CI configuration. I don't know if it's possible to have different runbot configuration for different branches of a same repository. (don't know if a runbot is required for the new openupgrade design...)
  • if a user git fetch the repo, all the old odoo code will come.
  • modules will not be visible by default on OCA appstore because of such configuration that exists to avoid having all odoo modules on the appstore. (that can be changed, but requires some extra work)

@pedrobaeza
Copy link
Member

Please see my last comment.

@legalsylvain
Copy link
Contributor Author

Please see my last comment.

Yes we wrote in the same time !

new layout, with 4 folders .... framework folder with openupgrade_framework

I don't like to have subfolder, as it will generate extra work / custom configuration regarding CI, pre-commit, etc.., having module in the root directory is simplier.
So not ./framework/openupgrade_framework/ but simply ./openupgrade_framework
don't you think ?

doc folder, with new instructions on how to make it work (conf with server-wide, upgrade-paths and so on), and the migration coverage.

👍

I share @StefanRijnhart's PoV: 14.0 branch in OCA/OpenUpgrade

👍 again.

analysis folder with openupgrade_records module inside.

I still prefer my proposal ;-) (OCA/server-tools-or-whatever/upgrade_analysis).

  • As said in my previous comment, I don't think it's a "only-openupgrade-tools".
  • I also think that CI of upgrade_analysis (openupgrade_records) is totally different of the rest of the project.

This module :

  • requires "classical test" to know if it works correctly (if records are correctly created). Also maybe adding a mook to test connection...
  • proposing it on the OCA runbot platform makes sense.

On the contrary, for framework and migration script,

  • tests should be tested with a N-1 database, to check if all scripts are correct.
  • Runbot doesn't make sense.

But I totally agree with this approach and excited to have it. Thanks for catching what I had in my mind since a long and make it real.

Thanks ! Also very excited ! I hope that this lighter project will bring in more contributors.

@StefanRijnhart
Copy link
Member

The analysis module can not reside in any other repo like server-tools, because then the monkeypatches will affect everybody who's got that repo in their addons path. Thinking again, I think a separate repo for the analysis module would be nice and the rest can go in a single repo as far as I'm concerned (easy to update the module coverage in the same PR as the migration scripts).

@StefanRijnhart
Copy link
Member

Oh, to be honest in the case of the analysis module the monkey patches can be activated in a post load hook. Would still be nice to have it separated so that it can be maintained/ported independently from the rest of the framework.

@pedrobaeza
Copy link
Member

I still think that everything can go together, as the same procedure for migrating a module (preserving commit history) can be applied here. The burden of maintaining other repo is not worth IMO. About tests, they can be perfectly done through different builds, and there's no problem on applying them even in the same repo. Anyway, we don't have any test right now, and mocking all the communication is a nonsense here, as it depends a lot on both versions.

@legalsylvain
Copy link
Contributor Author

legalsylvain commented Nov 5, 2020

The analysis module can not reside in any other repo like server-tools, because then the monkeypatches will affect everybody who's got that repo in their addons path.

Hi @StefanRijnhart. That was true before, but not anymore, and since at least version 12. Something has been "fixed" somewhere between 8 & 12 version. I just discovered that point, working on that PR. See :

Step to reproduce :
write the following text at the end of the file ./odoo/addons/sale/__init__.py

print("==========================")
print("Executed !!!")
print("==========================")

Then : execute on a fresh created DB (with createdb)

  • step 1 -i product
  • step 2 -i sale

Result :

V8

during step 1, the code is executed, just after the installation of the base module.

2020-11-05 16:51:55,836 24099 INFO database_v8 openerp.modules.loading: loading base/res/res_partner_demo.xml
2020-11-05 16:51:56,751 24099 INFO database_v8 openerp.modules.loading: loading base/res/res_partner_demo.yml
2020-11-05 16:51:57,976 24099 INFO database_v8 openerp.modules.loading: loading base/res/res_partner_image_demo.xml
2020-11-05 16:51:59,132 24099 INFO database_v8 openerp.modules.loading: 1 modules loaded in 12.35s, 0 queries
2020-11-05 16:51:59,242 24099 INFO database_v8 openerp.modules.loading: updating modules list
2020-11-05 16:52:03,110 24099 INFO ? openerp.addons.bus.bus: Bus.loop listen imbus on db postgres
2020-11-05 16:52:03,711 24099 INFO database_v8 openerp.addons.report.models.report: Will use the Wkhtmltopdf binary at /usr/local/bin/wkhtmltopdf
==========================
Executed !!!
==========================
2020-11-05 16:52:04,349 24099 INFO database_v8 root: Unable to import odoorpc, used in base_import_odoo
2020-11-05 16:52:04,941 24099 INFO database_v8 openerp.http: HTTP Configuring static files
2020-11-05 16:52:07,866 24099 INFO database_v8 openerp.modules.loading: loading 23 modules...
[...] 

V12

Step 1 : no text is displayed.
Step 2 : text is displayed, at the beginning of the installation of sale. (just after payment_transfer)

2020-11-05 16:54:46,324 24758 INFO database_v12 odoo.modules.loading: loading payment_transfer/data/payment_acquirer_data.xml 
2020-11-05 16:54:46,372 24758 INFO database_v12 odoo.modules.loading: Module payment_transfer: loading demo 
==========================
Executed !!!
==========================
2020-11-05 16:54:46,629 24758 INFO database_v12 odoo.modules.registry: module sale: creating or updating database tables 
2020-11-05 16:54:47,075 24758 INFO database_v12 odoo.models: Storing computed values of sale.order.invoice_status 
2020-11-05 16:54:47,076 24758 INFO database_v12 odoo.models: Storing computed values of sale.order.amount_untaxed 

V14

Same behaviour.
Step 1 : nothing is displayed.
Step 2 :

2020-11-05 16:56:30,951 25118 INFO database_v14 odoo.modules.loading: loading payment_transfer/data/payment_acquirer_data.xml 
2020-11-05 16:56:30,968 25118 INFO database_v14 odoo.modules.loading: Module payment_transfer: loading demo 
2020-11-05 16:56:30,986 25118 INFO database_v14 odoo.addons.openupgrade_framework.odoo_patch.odoo.modules.loading: Module payment_transfer loaded in 0.27s, 122 queries 
2020-11-05 16:56:30,986 25118 INFO database_v14 odoo.addons.openupgrade_framework.odoo_patch.odoo.modules.loading: Loading module sale (41/41) 
==========================
Executed !!!
==========================
2020-11-05 16:56:31,248 25118 INFO database_v14 odoo.modules.registry: module sale: creating or updating database tables 
2020-11-05 16:56:31,751 25118 INFO database_v14 odoo.modules.loading: loading sale/security/sale_security.xml 
2020-11-05 16:56:31,916 25118 INFO database_v14 odoo.modules.loading: loading sale/security/ir.model.access.csv 

Finally, with a new fresh database, in V14, if you make -i product BUT, set server_wide_modules = sale.

Result : the code is executed before the installation of base.

2020-11-05 17:06:41,437 26132 INFO ? odoo: database: odoo14@default:default 
2020-11-05 17:06:42,042 26132 INFO ? odoo.addons.base.models.ir_actions_report: Will use the Wkhtmltopdf binary at /usr/local/bin/wkhtmltopdf 
==========================
Executed !!!
==========================
2020-11-05 17:06:42,326 26132 INFO ? odoo.service.server: HTTP service (werkzeug) running on sylvain-grap:8014 
2020-11-05 17:06:42,336 26132 INFO ? odoo.modules.loading: init db 
2020-11-05 17:06:43,353 26132 INFO database_v14_with_server_wide_modules odoo.modules.loading: loading 1 modules... 
2020-11-05 17:06:43,354 26132 INFO database_v14_with_server_wide_modules odoo.modules.loading: Loading module base (1/1) 
2020-11-05 17:06:43,427 26132 INFO database_v14_with_server_wide_modules odoo.modules.registry: module base: creating or updating database tables 
2020-11-05 17:06:44,333 26132 INFO database_v14_with_server_wide_modules odoo.models: Storing computed values of ir.module.module.menus_by_module 

am I wrong, or can we consider now that monkey patches are not dangerous in a module of a folder present in the addon path, if the module is not installed ?

Edit : March, 17 2021

Context :

  • having a monkey patch in a module module_with_monkey_patch, available in the addons path.
  • having 2 databases (db1, db2) running in the same environment (same code, same process(es), same odoo.cfg file)
  • install module_with_monkey_patch on db1, and do not install module_with_monkey_patch on db2.

Result :

  • the monkey patch is executed on db2, when the module is not installed and not present in the server_wide_modules option.

Note :

  • IMO, that doesn't matter in the Openupgrade refactor context, because the module with monkey patches (openupgrade_framework) should never be installed, but loaded with server_wide_modules option. So in that case, it is normal that the monkey patches are executed for all the databases of the environment.

@yajo
Copy link
Member

yajo commented Nov 6, 2020

So, @pedrobaeza, @yajo : is this what you had in mind ?

Most likely yes! Sorry to be late to the party. This would be great and you have my support! 👍

1) openupgrade_analysis :

* renamed into `upgrade_analysis`

* move into `OCA/server-tools` (as other analysis modules exist for the time being, like https://github.com/OCA/server-tools/tree/12.0/module_analysis).

It's an addon, and has possibly more usages outside of openupgrade... so it goes in addons repo. Simple. I like it. 👍

2) openupgrade_framework and openupgrade_script

maybe merged into a single one module. (I don't see user case when developper want to have one module without the other.

I had in mind 2 different strategies.

First would be to just monkey-patch everything in scripts/base/pre-monkey_patch_odoo.py. It runs before base updates, so it seems a good place to introspect what modules are available and apply any needed monkey patches. And we avoid the need to have a separate module.

If that approach doesn't work because it monkey-patches bottom-up, and instead it's absolutely needed to monkey-patch stuff before even the module loading system boots, then my 2nd approach would be to create a new script. Let's call it odoo-update. This script would be something in the lines of this pseudocode:

import click
import click_odoo
from click_odoo import odoo, OdooEnvironment
from unittest import mock
from contextlib import contextmanager


@contextmanager
def PatchedOdooEnvironment(*args, **kwargs):
    """Patch Odoo and then load its env.

    Specific implementation might differ among versions. No need to have multiple branches.
    """"
    with mock("odoo.modules.loading", ...), mock(...):
        yield OdooEnvironment(*args, **kwargs)


@click.command()
@click_odoo.env_options(environment_manager=PatchedOdooEnvironment)
@click.argument("upgrades_paths", type=click.Path(exists=True, readable=True, file_okay=False, dir_okay=True)
def main(env, upgrades_paths):
    ...  #Run odoo update in the mocked env

if __name__ == '__main__':
    main()

Of course it could be done without click-odoo, but I think the commodities it supplies justify its usage.

This would be a separate repo. Just a normal python package that you could install through pypi and wraps your current odoo installation, mocks it, and runs odoo in -u all mode behind the scenes. This way we make sure all monkey-patches are applied top-down.

@pedrobaeza
Copy link
Member

click-odoo is outside OCA and can't be used according OCA rules. And I personally don't want to have yet another library for this.

About the module being in OCA/server-tools, it doesn't serve for anything except OpenUpgrade, and it will conflict for sure with the rest of the normal modules. I don't see why we have to make the effort to put it there while it can be kept here, everything together, but still, separated.

@sbidoul
Copy link
Member

sbidoul commented Nov 6, 2020

click-odoo is outside OCA

If that can help we can propose it to OCA anytime. Let me know.

@StefanRijnhart
Copy link
Member

Thanks @legalsylvain, looks like the monkeypatching problem is solved indeed.

About click-odoo, if I understand correctly it implies installing odoo as a python package. Not everybody installs Odoo like that so I would prefer not to add that dependency.

@sbidoul
Copy link
Member

sbidoul commented Nov 6, 2020

About click-odoo, if I understand correctly it implies installing odoo as a python package

No it does not. All it needs is that import odoo works with the python interpreter used to launch it.

@rvalyi
Copy link
Member

rvalyi commented Nov 6, 2020

Also about click-odoo not being OCA. I don't see such a big deal here. As Pedro said starting to host pure Python/non Odoo packages inside OCA repos may suck (because it is very different). But other than that, many OCA modules rely on pure Python packages hosted elsewhere, why would click-odoo be such a problem?

@pedrobaeza
Copy link
Member

Well, it's only a question of balance: what click-odoo brings as benefit to OpenUpgrade against having to deal with spread code across several places that can provoke conflicts, regressions, etc.

Anyway, I'm in favor of moving click-odoo under the OCA umbrella (but for other things). We are using it on Dooba and it's an excellent work by Acsone.

@yajo
Copy link
Member

yajo commented Nov 6, 2020

I've had the experience of scripting with click-odoo and without it, and put simply: it's better. 🤷‍♂️ It's just a library that makes odoo scripting more comfortable and I agree with @rvalyi. The same way we rely on pylint to provide our pylint-odoo instead of writing our own linter from scratch, we can rely on click-odoo to write our CLI tool that alters odoo for update commodities.

In any case, before talking about the specific implementation details (remember that was just pseudocode), I think we should focus in the main subject: how to better inject the mocks? Current options are:

  1. A module.
  2. A pre-migration script in base.
  3. A separate CLI tool that acts as a wrapper.

I guess option 3 would be best overall. I think options 1 and 2 would end up leading to some ugly workarounds sooner or later. Well... monkey patching is always ugly, but you get what I mean...

@pedrobaeza
Copy link
Member

I agree about using option 3, but not about putting that wrapper depending on click-odoo. Doing that, we will find that version X of such library doesn't work with OpenUpgrade by any reason. I prefer to encapsulate the needed code here. But all approaches as always have trade-offs.

@legalsylvain
Copy link
Contributor Author

Hi @pedrobaeza

About the module being in OCA/server-tools, it doesn't serve for anything except OpenUpgrade, and it will conflict for sure with the rest of the normal modules. I don't see why we have to make the effort to put it there while it can be kept here, everything together, but still, separated.

As said before, I think this module can be used in a non OpenUpgrade context

Use case 1

A developper works on an 12.0 instance and wants to refactor fully a custom module. he realizes the job and then run the update_analysis module on a V12.0 test instance (with old module) and a V12.0 test instance (with refactored module) and then generate the analysis file.
It can be helpfull to check that all the migrations are handled correctly. (specifically xml_ids renames, etc..)

Use Case 2

Customer has an Odoo EE enterprise instance on premise with custom modules (that inherit account.invoice) with an integrator (like C2C, Acsone, etc...) on 12.0. He want to migrate in 13.0.
The integrator migrates the custom modules, and then run update_analysis to see all the differences and write the migration script.
then the migration is realized

  • with Odoo SA private scripts (for the official addons)
  • with the migration scripts of the custom modules (for the custom modules).

My assumption is that the current openupgrade_records module is not used for such purpose because it is higly hidden in a technical project named Openupgrade, deeply in /odoo/odoo/addons/base folder and the name suggests that it is only useful for OpenUpgrade. So only a few people that maintains that repositories know the existence of the module. I use Openupgrade since V6.1 -> V7.0 migration, but began to understand how it works only now.
Making this module more standard and visible in a popular repository like server-tools could allow a more large usage.

As said, there is no risk, regarding monkey patches.
Regarding the history,

  • we can commit the module with an initial git commit --author="xxx". (I guess @StefanRijnhart, ref)
  • BTW, it doesn't seems the history is preserved until today. see for exemple the V13 history of openupgrade_records in V13. the first commit begin in 2019...History of V8 seems to have been lost.
  • we can live with that.

@yajo :

Most likely yes! Sorry to be late to the party. This would be great and you have my support! +1

Thanks !

I had in mind 2 different strategies.

I have no point of view regarding both strategies, and I don't use click-odoo ! so I abstain on that point, and I'll have to test click-odoo to understand your proposal. I'll be back in a couple of weeks ! ;-)

First would be to just monkey-patch everything in scripts/base/pre-monkey_patch_odoo.py

I just prefer to avoid a single file. for having ported the code from version 13 to version 14, it is really simple to have the same tree for official odoo project and for the patches bundle. Using meld is so very easy to check the differences.

Anyway, thank you all for your enthusiasm !

@pedrobaeza
Copy link
Member

OK, Sylvain, as you prefer, as you are the one pushing this, and I agree such use cases can apply. My only fear is the CI on that repo, but let's see.

@sbidoul
Copy link
Member

sbidoul commented Nov 6, 2020

how to better inject the mocks

  1. module.
  2. pre-migration script in base.
  3. separate CLI tool that acts as a wrapper.

I'm probably not qualified to say anything here, but if option 1 is talking about a module that patches other modules I'll just say it sounds a bit scary. Option 3 is probably easier to understand for muggles :)

@ivantodorovich
Copy link

I also think option 3 makes more sense. IMO both features could be implemented in a script (using click-odoo or not, although I would use it -- why re-develop something that works?)

I imagine something like a cli tool with these commands:

  • openupgrade analysis -d <db_name> ... etc
  • openupgrade upgrade ..

I don't see why these features should be packed in an odoo module, they're not meant to be deployed in prod/staging/dev databases afterall.. they're just tools

@pedrobaeza
Copy link
Member

@ivantodorovich for analysis, you can't do that, as it needs a very previous setup + 2 Odoo runnings (previous version and current one), so it must split from this "script", and also with the use cases depicted by Sylvain, you don't have the same previous setup.

@legalsylvain
Copy link
Contributor Author

  1. module.

Well. For having tested this implementation. (still WIP)

  • it seems to work (patches are loaded at the beginning, before loading base module.)
  • i saw the following procedure very easy to explain to all people that want to use this project

A) pull a regular odoo (of the targeted branch)
A') install openupgradelib
B) add the openupgrade repo in your addons path
C) add openupgrade_framework in your server_wide_modules of your odoo.cfg
D) update all
E) remove openupgrade_framework from your server_wide_modules.
F) enjoy or repeat and debug or G)
G) pay if some scripts are not working or developped ;-)

I mean that all people hosting an odoo can do that.

Make open upgrades simple (as far as it's possible ...) AND accessible should be one of the objective of openupgrade maintainers. We have to keep in mind that openupgrade (migration scripts part) is for the time being, a project that is quite hard to sustain (in a financial point of view). Having more contributors and a simpler tool could bring in more people.

they're not meant to be deployed in prod/staging/dev databases afterall

Yes, it's just one of the easy ways to deploy openupgrade framework, but this module doesn't have to be installed indeed.

But again, I don't understand the other options ! so .. no problem if you think it's better ;-)

Side question : @sbidoul : what is muggles ? deepl.com doesn't help me.

@pedrobaeza
Copy link
Member

https://en.wikipedia.org/wiki/Muggle - Harry Potter's freak terminology 😉

Thanks for the extra explanation. Then 1 seems very good with server_wide_modules declaration. I'd go definitively to that way, as it doesn't have extra burden.

@kos94ok-3D
Copy link

kos94ok-3D commented Nov 6, 2020

What do you think about adding an environment variable in openupgrade_framework?
Is it can help or all is OK?

if os.environ.get('OPENUPGRADE_MONKEY_PATCH'):
  BaseModel.load = _load

@StefanRijnhart
Copy link
Member

Thanks for clarifying @legalsylvain. I have become quite curious to look into click-odoo given all the praise that it receives in this thread, but if we can pull it off with vanilla Odoo (and I'm sure we can, speaking as someone who has ample experience with dirty monkeypatching in Odoo) that has its merits too.

@yajo

This comment has been minimized.

@rvalyi

This comment has been minimized.

@legalsylvain

This comment has been minimized.

@kos94ok-3D

This comment has been minimized.

@pedrobaeza

This comment has been minimized.

@yajo
Copy link
Member

yajo commented Nov 6, 2020

OK we can do a dumber poll. Just add a reaction to this message:

  • 🎉 module
  • 👀 pre-migration script
  • 🚀 Specific CLI app

Edit note: I have hidden all comments related to the old poll, to keep this focused. Let's use this other one which is simpler and more secure. 😊

@legalsylvain

This comment has been minimized.

@StefanRijnhart
Copy link
Member

StefanRijnhart commented Dec 6, 2020

@legalsylvain's approach works very well. It has forced me to review all patched previously included in OpenUpgrade and I believe most of them could be dropped. I've been spending my corona quarantine on this task and I now have a working setup.

openupgrade_records is moving to server-tools/upgrade_analysis here: OCA/server-tools#1941

I have proposed the following PRs onto Sylvain's branches:

I think we should proceed by pushing Sylvain's openupgrade_framework branch as oca/openupgrade/14.0 and move these PRs there.

A small change in openupgradelib is necessary to run the migration

Two Three tasks are left to develop further:

  • Integrate the generation of noupdate changes xml files in upgrade_analyis (and stop it from listing deleted values for deleted fields).
  • Try and find a sensible CI setup and methodology to test migration scripts (I dropped the related patches for now)
  • Add the docs in the openupgrade-framework branch, and add a module coverage page for the new edition.

@yajo
Copy link
Member

yajo commented Dec 7, 2020

Thanks for your work guys, I've reviewed them all.

@legalsylvain
Copy link
Contributor Author

Thanks @StefanRijnhart for this work, and the summary.

I think we should proceed by pushing Sylvain's openupgrade_framework branch as oca/openupgrade/14.0 and move these PRs there.

I don't know how to proceed, and I'm not comfortable with such tasks (creating new branch, initialize correctly OCA repo). Do I have to do something, or should I just wait until a 14.0 branch is available to make a new PR ?

Three tasks are left to develop further:

  • Integrate the generation of noupdate changes xml files in upgrade_analyis (and stop it from listing deleted values for deleted fields).

I'm not sure to understand that point technically. But if I can help...

  • Try and find a sensible CI setup and methodology to test migration scripts (I dropped the related patches for now)

I created a dedicated issue to talk about the CI and the new design. #2476

  • Add the docs in the openupgrade-framework branch,

I'll copy paste the old doc folder in the new branch at root level. Maybe some update should be applied, but I think it can be done in a second time, and we can talk about this point in a separate issue.

and add a module coverage page for the new edition.

Regarding that point, i searched for a script that had generated the previous files (sample) but i did found any, in openupgrade project.
Is there such a script? or the files has been created manually ?
If not, I think we could develop a little script and add it in the upgrade_analysis module.

@StefanRijnhart
Copy link
Member

Integrate the generation of noupdate changes xml files in upgrade_analyis (and stop it from listing deleted values for deleted fields).

@StefanRijnhart
Copy link
Member

@legalsylvain and I are proposing the OpenUpgrade framework and analysis into oca/openupgrade/14.0 here: #2482

@legalsylvain
Copy link
Contributor Author

legalsylvain commented Mar 17, 2021

Hi.
For your information. I just faced (in a non openupgrade context) a case where a monkey patch is loaded, when I didn't think it would be.

I added the context in a note at the end of this comment here.

As said, I don't think there is a negative impact on the openupgrade V14 design.

CC : @StefanRijnhart

regards.

@StefanRijnhart
Copy link
Member

Thanks. That is indeed how I understand monkey patching to work. And you are right that it does not affect OpenUpgrade 14 because we use server_wide_modules. In upgrade_records we use the patching decorator to minimize impact, but it may be the case that a simultaneous upgrade of a different database is affected. That should be a rare situation though.

@rvalyi
Copy link
Member

rvalyi commented Oct 19, 2021

@legalsylvain I think this issue can now be closed, no?
cc @StefanRijnhart @pedrobaeza

@legalsylvain
Copy link
Contributor Author

Indeed !

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

No branches or pull requests

9 participants