Repository navigation
[20.0][MIG] base - #6068
[20.0][MIG] base#6068hbrunn wants to merge 75 commits into
Conversation
If we don't include it, /jsonrpc route doesn't work.
If you have a module in previous versions that adds data on a model,
and such model is not loaded in the registry in current version because
the module is absent in it, you can't uninstall such module, getting
this error:
File "odoo/odoo/addons/base/models/ir_model.py", line 1945, in _module_data_uninstall
delete(self.env[model].browse(item[1] for item in items))
File "odoo/odoo/api.py", line 463, in __getitem__
return self.registry[model_name]._browse(self, (), ())
File "odoo/odoo/modules/registry.py", line 177, in __getitem__
return self.models[model_name]
KeyError: 'model'
With this patch, data cleanup of such model is skipped and there's no crash.
…ore ; add links to the new OpenUpgrade website
If corresponding field is None, we need to avoid the "AttributeError: 'NoneType' object has no attribute error.
…rg validate as it is not anymore in odoo 15
…e useless after the input argument validate has been removed
Because we captured the exception in _raise_view_error and archived that
view, so info is None, but it is called to info.get('select') in
NameManager.check, which will raise an exception AttributeError, so we
need to override to not raise an exception
mauro2306
left a comment
There was a problem hiding this comment.
Functional test outside CI at 1faabaf, which includes #6046. A first run at 2d9eb6b on 2026-10-30 gave the same results.
Setup:
- Official
odoo:20Docker image and PostgreSQL 17. - Source: a fresh v19 database with the 88 modules of three production Community databases (account, account_peppol, l10n_be, stock_account, sale_stock, project…), plus
scripts/base/tests/data_base_migration.pyand some data of our own (bank account, Peppol endpoints, tracked changes, a posted invoice). - Same procedure as
test-migration.yml: modules not marked Done are set to uninstalled, then--load=base,web,openupgrade_framework --test-enable --test-tags openupgrade --update=base. - openupgradelib 3.13.7 with the change of OCA/openupgradelib#468 applied. Without it, the post-migration fails in
load_data(), so this needs an openupgradelib release that includes it.
Result:
- As is, the migration fails in
end-migration.pywithKeyError: 'discuss.channel'(see the line comment). - With that fixed, it completes and the 3 tests pass (
0 failed, 0 error(s) of 3 tests). Theres_partner_bankdata is kept:account_numberholds the formeracc_numbervalue. - 6
ir.accessrecords are created as "Migrated from v19", and 2 of them have nogroup_id(operationsrandd), which matches @MiquelRForgeFlow's remark about falling back tobase.group_everyone.
carlosdauden
left a comment
There was a problem hiding this comment.
Reviewed at 1faabaf against origin/20.0, line by line against the base scripts we run on our 20.0 integration branch (19.0 -> 20.0 migration of the OCA test database with ~420 module scripts on top, 132 migration tests, Python 3.12 / PostgreSQL 16). Thanks for the work on the ir.access conversion, it is the hardest part of this module. Every point below was checked against the 19.0 and 20.0 code; happy to open a PR against your branch with our versions of the fixes.
Changes I would ask for:
-
res_device_log:user_id = -1violates the 19.0 foreign keyres_device_log_user_id_fkey(ON DELETE SET NULL). It is still there after the update: the 20.0 field is a plainInteger, and the schema update never drops a foreign key the model no longer declares. So the pre-migration aborts on any database where a user with device logs was deleted, and after the migration, deleting a user with logs fails (SET NULL against the new NOT NULL). Suggestion: drop the foreign key onres_device_log.user_id(found throughpg_constraint) and itsir_model_constraintrow, and delete the rows withuser_id IS NULLinstead of filling them (the log of a deleted user has no value). -
end-migration.py:env.ref("mail.channel_admin", raise_if_not_found=False)raisesKeyError: 'discuss.channel'when the source database hadmailinstalled, because the xmlid exists but the model is not loaded while base is updated (thetest-migration.ymlsetup). mauro2306 reproduced it; the guard"discuss.channel" in env and env.ref(...)from that comment fixes it. -
API keys: 20.0 only accepts a key for the scope it was generated for (
scope = %(scope)sin_check_apikey_credentials, 61c8515704ca), while 19.0 also acceptedscope IS NULLfor any scope, which is how every key generated from the user preferences is stored. After the migration all those keys stop working for RPC. The analysis does not show it becauseres_users_apikeysis_auto = False.UPDATE res_users_apikeys SET scope = 'rpc' WHERE scope IS NULL(the scope 20.0 gives to keys created from the same screen). -
res_partner_bank:- The update from
res_banksetscountry_id = res_bank.country, which wipes the country of every account whose bank has none (or has no bank). UseCOALESCE(res_bank.country, res_partner_bank.country_id). clearing_label_idis new, required, precompute and stored, but theclearing.labeldata is not loaded yet when the column is created, so it stays NULL on every existing account. It needs a fill like_compute_clearing_label_idonce base data is loaded (label of the account's country, elsebase.clearing_label_all); in SQL to avoid writing every account and running the 20.0 clearing number constraints on legacy data.
- The update from
-
res_country.zip_applicability: the post-migration loadsnoupdate_changes.xml(which sets the 20.0 values, includingnot_applicablefor countries such as ao, bz or hk) and then mapsNOT zip_requiredtooptional, overwriting those values. Map first, then apply the 20.0 value only to the countries whosezip_requiredis still the 19.0 data value, so user changes are kept. -
noupdate_changes.xmlhas entries that should not be applied as they are:main_partneris_company = Falseis a generator artefact:is_companybecame a stored compute in 20.0. Loading it turns the main company partner into a person. Please remove it.- UZS
symbol(96cfcaac7429) andbase.default_max_email_sizeare overwritten unconditionally. Update them only where the 19.0 value is unchanged (symbol = 'лв', value10), so user changes survive. - Related:
ir.mail_server.max_email_sizeis removed (left unannotated in the work file) and 20.0 only readsbase.default_max_email_size. When a 19.0 server had its own size, the parameter should get the smallest size an active server accepted, so no mail becomes bigger than what a server took before.
-
ir.accessconversion: MiquelRForgeFlow's comments of 2026-11-03 are still open at 1faabaf:- add
studio_customizationto the custom xmlid modules (3 places); - fall back to
base.group_everyonefor a model access without group (in 19.0 it grants everyone, in 20.0 anir.accesswithout group is a restriction; mauro2306 got 2 such records); - add the domains of the standard rules of the group and its implied groups to the migrated access of manual models;
- a savepoint per
create()(inactive record and a warning on failure) instead of disabling_validate_fields, which can leave invalid domains active; - more useful names than "Migrated from v19" for every record, since the end-migration asks admins to review them;
- repoint the
__export__/__custom__xmlids of the sourceir.model.access/ir.rulerows to the created records; - move
ir_access()to end-migration, when every model, the moduleir.accessdata and the group implications are loaded.
- add
-
CI:
- "test" fails before running anything: the workflow uses Python 3.10, so odoo-old cannot import
babel. 20.0 needs Python 3.12 and PostgreSQL 16 in.github/workflows/test-migration.yml. - "test with Odoo" and "test with OCB" fail because the branch carries an old copy of the #6046 framework test, without
mute_logger("odoo.modules.module"), which logs "manifest not found" foropenupgrade_framework_test_auto_install. Rebasing on the current #6046 head fixes it. - pre-commit needs the pylint-odoo bump to v10.0.12 (OCA/pylint-odoo#590), as in #6046.
- CLA: same history commits as #6046.
- "test" fails before running anything: the workflow uses Python 3.10, so odoo-old cannot import
-
Depends on OCA/openupgradelib#468 (approved, not merged) for
load_data, as FerDeNetlab and mauro2306 noted.
Not blocking, can be follow-ups:
-
States (
res.country.state.csvin 20.0). Besides Odisha, Ladakh and the 2 Egypt merges:- India:
state_in_dd(Daman and Diu) is gone, merged intostate_in_dn. - Lebanon: the
l10n_lb_accountstates move to base with ISO codes (state_lb_01->base.state_lb_ak, ...), and their Arabic duplicates (state_lb_02_ar, ...) are removed. - Bahrain and Oman: the
l10n_bh/l10n_omstates move to base with ISO codes (l10n_bh.state_bh_1->base.state_bh_13,l10n_om.state_om_01->base.state_om_mu, ...). - Saudi Arabia: the 93 city "states" are replaced by the 13 regions; at least the cities that name a region or its capital can be merged (
state_sa_70Riyadh ->state_sa_001, ...).
Without renames or merges, base creates duplicates, and
_process_endcannot delete the old states still used by partners (ondelete='restrict'). The Egypt merge works, but it runs in pre-migration under theversion_info = (19,)hack; done in post-migration withmerge_records(method="sql")it needs no hack. We have the full mapping and can contribute it. - India:
-
Timezones: only 3 values are mapped. The 20.0 selection comes from
zoneinfofiltered by babel (odoo/tools/date_utils.pyall_timezones), so depending on the server tz database every backward link (US/Eastern, Asia/Calcutta, CET, ...) can disappear, andtz_offsetcallsZoneInfo(tz)unguarded. A mapping table built once in base from the tz database links (only links missing from the selection whose target exists) can be reused by the modules owning other tz columns (resource_calendar,resource_resource,calendar_recurrence,mail_guest,event_event,hr_version, ...). The KGS symbol (c78dead6b43e, also in 19.0 but noupdate) can get the same "only if unchanged" update as UZS. -
t-escis removed from server QWeb in 20.0 and renders nothing. Custom views, edited copies of standard views and mail templates keep it after the migration. At-esc->t-outrewrite in base end-migration (ir_ui_view.arch_db/arch_prev,mail_template.body_html/subject) covers all modules at once. -
company_registry->additional_identifiers: skip empty strings, do not overwrite an existing key, and use the enterprise number key of the partner's country when there is one,OTHERotherwise. -
group_user_regularis only added to direct members ofbase.group_user, so users that get it through an implied group are missed. Low impact, as 19.0 stores direct groups only, butNOT shareonres_usersis simpler and covers everything. -
Nit: the
ir_exports_lineid -> sequence copy is not needed (_order = 'sequence, id'with the default sequence keeps the order). Harmless.
|
@MiquelRForgeFlow attended all your comments where I agree, added a reply otherwise |
| Do not consider interactions between v19 provisioned rules and custom rules, as the | ||
| goal here is to just migrate the custom v19 rules, not to restore the exact | ||
| permissions existing in v19. |
There was a problem hiding this comment.
I understand, but skipping standard rules can widen access silently. Example: in v19, a custom ACL gives unlink on sale.order to sales_team.group_sale_salesman, and the standard sale.sale_order_personal_rule limits it to the salesman's own orders. Here it becomes a domain-less permission, so in v20 the salesman can delete every order. Could we at least add the domains of the standard group rules that applied to the ACL's group (and the groups it implies) to the permissions created from custom ACLs? If you'd rather not, could the admin message say explicitly that custom model access on models with standard record rules now grants access to all records?
There was a problem hiding this comment.
I'd rather not, this will create a huge mess. Isn't my "Be especially cautious with group based restrictions, those will most likely not work the way they used to." clear enough?
There was a problem hiding this comment.
Agreed that merging the standard domains gets messy. But the risk is the opposite of the one the message warns about: here access gets wider, not narrower, and silently. A sentence about it after "Be especially cautious with group based restrictions..." in the admin message would make it explicit, e.g.:
<p>Custom model access for a group on a model with standard record rules for that
group now grants access to all its records: the domains of those standard rules
are not added to the migrated permission.</p>
carlosdauden
left a comment
There was a problem hiding this comment.
As asked, the points of my previous review as line comments, checked again on a3077e1 (the squashed [MIG] base). Thanks for moving the ir.access conversion to end-migration with a savepoint per record, the origin names, the group_everyone fallback, studio_customization and the discuss.channel guard: that covers my point 7 and mauro2306's KeyError. The suggestions are taken from the base scripts of our 20.0 integration branch, where the 19.0 -> 20.0 migration of the OCA test database passes with 132 migration tests; applied together on a3077e1 (with the current #6046 framework and the CI fixes below), the migration of the OCA test database passes too.
Points without a line in the diff, the CI is still red at a3077e1 for the same reasons:
- "test" fails before running anything (
ModuleNotFoundError: No module named 'babel'):.github/workflows/test-migration.ymluses Python 3.10 andpostgres:14.0; 20.0 needs Python 3.12 and PostgreSQL 16. - "test with Odoo" and "test with OCB" fail on "module openupgrade_framework_test_auto_install: manifest not found": the branch carries an old copy of the #6046 framework test. Rebasing on the current #6046 head fixes it.
- pre-commit needs the pylint-odoo bump to v10.0.12 (OCA/pylint-odoo#590), as in #6046. CLA: same history commits as #6046.
OCA/openupgradelib#468 is merged now, so load_data no longer needs anything here once the workflow installs openupgradelib from master.
| _merged_xmlids = [ | ||
| ("base.state_eg_su", "base.state_eg_gz"), | ||
| ("base.state_eg_hu", "base.state_eg_c"), | ||
| ] |
There was a problem hiding this comment.
Not blocking, can be a follow-up: besides Odisha, Ladakh and these two Egypt merges, res.country.state.csv changes more states in 20.0:
- India:
state_in_dd(Daman and Diu) is gone, merged intostate_in_dn. - Lebanon: the
l10n_lb_accountstates move to base with ISO codes (state_lb_01->base.state_lb_ak, ...), and their Arabic duplicates (state_lb_02_ar, ...) are removed. - Bahrain and Oman: the
l10n_bh/l10n_omstates move to base with ISO codes (l10n_bh.state_bh_1->base.state_bh_13,l10n_om.state_om_01->base.state_om_mu, ...). - Saudi Arabia: the 93 city "states" are replaced by the 13 regions; at least the cities that name a region or its capital can be merged (
state_sa_70Riyadh ->state_sa_001, ...).
Without renames or merges base creates duplicates, and _process_end cannot delete the old states still used by partners (ondelete='restrict'). The merges here also need the version_info = (19,) hack below; done in post-migration with merge_records(method="sql") they need none. We have the full mapping on our branch and can contribute it.
There was a problem hiding this comment.
there are TODOs for this in the work file, please PR your proposals after this is merged
| def res_device_log(env): | ||
| """ | ||
| Fill required columns | ||
| """ | ||
| for column, value in ( | ||
| ("first_activity", "create_date"), | ||
| ("ip_address", "'0.0.0.0'"), | ||
| ("last_activity", "create_date"), | ||
| ("user_agent", "'unknown'"), | ||
| ("user_id", -1), | ||
| ): | ||
| openupgrade.logged_query( | ||
| env.cr, f"UPDATE res_device_log SET {column}={value} WHERE {column} IS NULL" | ||
| ) |
There was a problem hiding this comment.
user_id = -1 violates the 19.0 foreign key res_device_log_user_id_fkey (ON DELETE SET NULL), so this aborts on any database where a user with device logs was deleted. The key also survives the update (the 20.0 field is a plain Integer, and the schema update never drops a foreign key the model no longer declares), so after the migration deleting a user with logs fails: SET NULL against the new NOT NULL. This drops the key and its ir_model_constraint row, and deletes the logs of users deleted in 19.0 (no value without the user), as we do on our branch.
| def res_device_log(env): | |
| """ | |
| Fill required columns | |
| """ | |
| for column, value in ( | |
| ("first_activity", "create_date"), | |
| ("ip_address", "'0.0.0.0'"), | |
| ("last_activity", "create_date"), | |
| ("user_agent", "'unknown'"), | |
| ("user_id", -1), | |
| ): | |
| openupgrade.logged_query( | |
| env.cr, f"UPDATE res_device_log SET {column}={value} WHERE {column} IS NULL" | |
| ) | |
| def res_device_log(env): | |
| """ | |
| Fill required columns. user_id becomes a plain Integer, so the foreign key of the | |
| v19 many2one (ON DELETE SET NULL) is not dropped by the schema update: drop it, | |
| and the logs of users deleted in v19, which v20 cannot hold | |
| """ | |
| env.cr.execute( | |
| """ | |
| SELECT con.conname | |
| FROM pg_constraint con | |
| JOIN pg_class rel ON rel.oid = con.conrelid | |
| JOIN pg_attribute att | |
| ON att.attrelid = con.conrelid AND att.attnum = ANY(con.conkey) | |
| WHERE rel.relname = 'res_device_log' | |
| AND con.contype = 'f' | |
| AND att.attname = 'user_id' | |
| """ | |
| ) | |
| for (constraint,) in env.cr.fetchall(): | |
| openupgrade.logged_query( | |
| env.cr, | |
| sql.SQL("ALTER TABLE res_device_log DROP CONSTRAINT {}").format( | |
| sql.Identifier(constraint) | |
| ), | |
| ) | |
| openupgrade.logged_query( | |
| env.cr, | |
| "DELETE FROM ir_model_constraint WHERE name = %s AND type = 'f'", | |
| (constraint,), | |
| ) | |
| openupgrade.logged_query(env.cr, "DELETE FROM res_device_log WHERE user_id IS NULL") | |
| for column, value in ( | |
| ("first_activity", "create_date"), | |
| ("ip_address", "'0.0.0.0'"), | |
| ("last_activity", "create_date"), | |
| ("user_agent", "'unknown'"), | |
| ): | |
| openupgrade.logged_query( | |
| env.cr, f"UPDATE res_device_log SET {column}={value} WHERE {column} IS NULL" | |
| ) |
There was a problem hiding this comment.
we don't delete data if not absolutely unavoidable. I lift the constraint now, but keep the -1 for null. Could also be SUPERUSER_ID if -1 causes issues, but deleting those records is wrong
|
|
||
|
|
There was a problem hiding this comment.
20.0 only accepts an API key for the scope it was generated for (scope = %(scope)s in _check_apikey_credentials, 61c8515704ca), while 19.0 also accepted scope IS NULL for any scope, which is how every key generated from the user preferences is stored. After the migration all those keys stop working for RPC; the analysis does not show it because res_users_apikeys is _auto = False. With the call below.
| def res_users_apikeys_scope(env): | |
| """20.0 only accepts an API key for the scope it was generated for | |
| (``scope = %(scope)s`` in _check_apikey_credentials, commit 61c8515704ca, | |
| odoo/upgrade#10432); 19.0 also accepted keys without scope for any scope, | |
| which is how every key generated from the user preferences was stored. | |
| Give them the 'rpc' scope, the one 20.0 gives to the keys generated from | |
| the same screen, so that the integrations using them keep working. | |
| """ | |
| openupgrade.logged_query( | |
| env.cr, "UPDATE res_users_apikeys SET scope = 'rpc' WHERE scope IS NULL" | |
| ) | |
| # DONE: set from corresponding res.bank fields in post-migration | ||
|
|
||
| base / res.partner.bank / clearing_label_id (many2one) : NEW relation: clearing.label, required, hasdefault: compute | ||
| # NOTHING TO DO: will be computed by ORM |
There was a problem hiding this comment.
Not computed: when the column is created the clearing.label data is not loaded yet, so it stays NULL on every existing account (see end-migration).
| # NOTHING TO DO: will be computed by ORM | |
| # DONE: end-migration: filled in SQL, the clearing.label data is not loaded when the column is created |
There was a problem hiding this comment.
well not in the first pass, but it is computed eventually. added a test for that. and the migration is supposed to break when there's a wrong clearing number, that's up to the user to fix before running OU
|
|
||
|
|
There was a problem hiding this comment.
Not blocking: t-esc is removed from server QWeb in 20.0 and renders nothing. Custom views, edited copies of standard views and mail templates keep it after the migration, and a rewrite here covers all modules at once (tested on our branch).
| # A t-esc attribute, an XPath test on it (@t-esc) or an attribute name | |
| # (<attribute name="t-esc">), not t-escape or some-t-esc | |
| _T_ESC_PATTERN = r"(?<![\w.-])t-esc(?![\w-])" | |
| _T_ESC_COLUMNS = [ | |
| ("ir_ui_view", "arch_db"), | |
| ("ir_ui_view", "arch_prev"), | |
| ("mail_template", "body_html"), | |
| ("mail_template", "subject"), | |
| ("mailing_mailing", "body_arch"), | |
| ("mailing_mailing", "body_html"), | |
| ] | |
| def qweb_t_esc_to_t_out(env): | |
| """20.0 removes the deprecated QWeb directive t-esc (commit 2cdad8b831ec, | |
| odoo/upgrade#8493): a node using it renders empty, with only an "Unknown | |
| directives" warning in the log. t-esc compiled exactly as t-out in 19.0. | |
| Rewrite it in every view arch (noupdate templates such as | |
| portal.portal_share_template, website copies, user edits; the XPath | |
| expressions of inheriting views that targeted @t-esc) and QWeb mail | |
| bodies still holding it after the update, in every language. | |
| """ | |
| for table, column in _T_ESC_COLUMNS: | |
| env.cr.execute( | |
| """ | |
| SELECT data_type FROM information_schema.columns | |
| WHERE table_name = %s AND column_name = %s | |
| """, | |
| (table, column), | |
| ) | |
| row = env.cr.fetchone() | |
| if not row: | |
| continue | |
| query = sql.SQL( | |
| """ | |
| UPDATE {table} | |
| SET {column} = regexp_replace({column}, %(pattern)s, 't-out', 'g') | |
| WHERE {column} ~ %(pattern)s | |
| """ | |
| ) | |
| if row[0] == "jsonb": | |
| query = sql.SQL( | |
| """ | |
| UPDATE {table} | |
| SET {column} = ( | |
| SELECT jsonb_object_agg( | |
| t.key, | |
| CASE WHEN jsonb_typeof(t.value) = 'string' | |
| THEN to_jsonb(regexp_replace( | |
| t.value #>> '{{}}', %(pattern)s, 't-out', 'g' | |
| )) | |
| ELSE t.value END | |
| ) | |
| FROM jsonb_each({column}) t | |
| ) | |
| WHERE jsonb_typeof({column}) = 'object' | |
| AND strpos({column}::text, 't-esc') > 0 | |
| """ | |
| ) | |
| openupgrade.logged_query( | |
| env.cr, | |
| query.format(table=sql.Identifier(table), column=sql.Identifier(column)), | |
| {"pattern": _T_ESC_PATTERN}, | |
| ) | |
There was a problem hiding this comment.
I'm working on a reusable function for openupgradelib so that it's available for any migration script. Will also have to do the fa->material icon transition. I'll also opt for correctness over speed, as the version above will render all pages talking about t-esc nonsense.
Keep the fork's update_list guard, theme_common removal, and update_property column on top of the base migration script. Co-authored-by: André de Kock <[email protected]>
Rebuild on fork 20.0 after the OCA sync and PRs #1, #2, #3 and #12. Keep theme_common removal, update_property and the auto-install guard together with the base migration. Co-authored-by: André de Kock <[email protected]>
|
@carlosdauden followed up where we agree, replied otherwise. Please don't paste stuff we already know in the general comment, none of this is new or unknown. And for the diff comments, please refrain from suggesting code changes in the future, most of them are either obvious, incomplete or so non-canonical as to be wrong that they just add noise. |
|
In our 19.0 → 20.0 rehearsal, Settings failed to open because a retired module left an inherited view referencing a field missing in 20.0. Removing that stale view fixed it. Would a focused PR for that cleanup be useful? |
|
@wbsouza such cleanup isn't the job of the base module's migration script. Depending on the nature of the retired module, that's up to database_cleanup, an entry in apriori.py, or some migration script of your custom modules. |
depends on:
I'll rebase after those are merged and the
PR has been merged and generated the first updated analysis