[19.0][FIX] openupgrade_framework: survive fresh databases - #5954
[19.0][FIX] openupgrade_framework: survive fresh databases#5954MiquelRForgeFlow wants to merge 2 commits into
Conversation
|
Hi @StefanRijnhart, @legalsylvain, @hbrunn, |
hbrunn
left a comment
There was a problem hiding this comment.
why do you load openupgrade_framework during database installation in the first place?
| for pkg in self.graph: | ||
| if pkg.load_state != "to upgrade" and pkg.name in self.migrations: | ||
| self.migrations[pkg.name]["module"] = {} | ||
| self.migrations[pkg.name]["module_upgrades"] = {} |
There was a problem hiding this comment.
won't this break running migration script for newly installed dependencies?
There was a problem hiding this comment.
It shouldn't. Only module and module_upgrades are cleared, i.e. the migrations/ and upgrades/ folders shipped inside the addon itself. The upgrade key (upgrade_path, so openupgrade_scripts) is untouched, which is what 85923c2 forces the scripts for in the first place, so OpenUpgrade scripts for modules appearing in the new version still run.
What the addon's own scripts do for a module installed from scratch is nothing useful: pkg.load_version is empty, so parse_version('') sorts below everything and compare() matches every version folder. Installing l10n_ch on a 19.0 database runs its 9.0.9.0, 11.1, 11.2, 11.3 and 0.0.0 scripts in a row. The 9.0 one is what broke for me: it imports migrate_set_tags_and_taxes_updatable from account.models.chart_template, removed long ago (the same script exists in l10n_in, l10n_nl, l10n_pl and l10n_sg).
Modules that do inherit history are not affected, because they don't arrive without a version. On merges openupgradelib copies it over explicitly ("Conserve old_name's state if new_name is uninstalled", SET state=m2.state, latest_version=m2.latest_version), and renames keep the ir_module_module row, so both come in as to upgrade with a latest_version set.
That's really the invariant I'm after, so I've keyed the condition on it directly instead of on the state, which says what it means:
for pkg in self.graph:
if pkg.load_version or pkg.name not in self.migrations:
continueThere was a problem hiding this comment.
this reads very much like a bullshit generator is involved here, please don't do that.
as for the change itself: we need to support running scripts for newly installed addons that live out of the migration path (ie oca modules being added as new dependency), so I don't see how this is going to work
There was a problem hiding this comment.
You're right on both counts, sorry for the wall of text.
An addon that has to run its own script when it gets installed as a new dependency would lose it with my change, so it's too broad. Dropping it.
What actually broke for me is Odoo's own old scripts: with an empty installed_version every version folder matches, so installing l10n_ch on 19.0 runs its 9.0.9.0 script, which imports a function removed from account ages ago. Same script in l10n_in, l10n_nl, l10n_pl and l10n_sg. Ok if I just add those five to to_exclude, like analytic/1.2? Or would you prefer skipping version folders from older Odoo series for modules with no version in the database?
…ases The ir_model_fields#translate cleanup ran unconditionally in _update_from_database, but on a brand new database that table does not exist yet: base_data.sql does not create it, the ORM does later on while loading base. Initializing a database with openupgrade_framework loaded aborted the transaction with 'relation "ir_model_fields" does not exist'.
…h installs Forcing the upgrade scripts of every module in the graph also brought in the module's own migrations/ and upgrades/ scripts for modules installed from scratch, where an empty installed_version matches every version folder and the addon's whole script history runs. Installing l10n_ch on 19.0 failed on its 9.0.9.0 script, which imports a function removed from account long ago. Keep only the OpenUpgrade scripts from upgrade_path for modules without a version recorded in the database.
Because that's the documented setup: But I'd argue it's worth guarding regardless of my workflow. |
e9edab6 to
b4b0b66
Compare
it tells you to do one of both, with --load listed first |
The
ir_model_fields#translatecleanup ran before the table exists: on a brand new databasebase_data.sqldoes not create it, the ORM does later on. Guard it withtable_exists().Forcing the upgrade scripts of every module in the graph also ran the module's own historical migration scripts for modules installed from scratch, where
installed_versionis empty and thus every version folder matches. Installingl10n_ch,l10n_in,l10n_nl,l10n_plorl10n_sgfailed on their 9.0 scripts, which import a function removed fromaccountlong ago. Keep only the OpenUpgrade scripts fromupgrade_pathfor those modules.Found doing manual analysis from fresh database for #5953.