Skip to content

Fix remove early initialization of res.{partner,company,users}#25

Merged
fkantelberg merged 2 commits intomasterfrom
fix-remove_early_init_of_some_res_models
Mar 5, 2026
Merged

Fix remove early initialization of res.{partner,company,users}#25
fkantelberg merged 2 commits intomasterfrom
fix-remove_early_init_of_some_res_models

Conversation

@azoellner
Copy link
Member

@azoellner azoellner commented Mar 2, 2026

This early initialization was there to prevent exceptions caused by fetching values of (newly added) fields of those models that were not yet present in the database, but had already been added to the model on the Python side.

Unfortunately, this did run before any module migration. Consequently, a module's pre-migration, which should run before any module and module upgrade, did then run only after those models had already been updated.

Also, the early initialization as implemented did already come too late. It had to run before check_auto_install(), but did run only in update_changed(), a couple of code lines later.

In the end, it is unnecessary if prefetch_fields=False is in the context.

But the context_get() does not put this entry into the context.

This commit fixes all those issue. It makes the early initialization of the three models superfluous, and then removing it automatically let's the migration work as expected again.

This early initialization was there to prevent exceptions caused by
fetching values of (newly added) fields of those models that were not yet
present in the database, but had already been added to the model on the
Python side.

Unfortunately, this did run before any module migration. Consequently, a
module's pre-migration, which should run before any module and module
upgrade, did then run only after those models had already been updated.

Also, the early initialization as implemented did already come too late.
It had to run before `check_auto_install()`, but did run only in
`update_changed()`, a couple of code lines later.

In the end, it is unnecessary if `prefetch_fields=False` is in the context.

But the `context_get()` does not put this entry into the context.

This commit fixes all those issue. It makes the early initialization of the
three models superfluous, and thus automatically let's the migration work
as expected again.
@azoellner azoellner requested a review from fkantelberg March 2, 2026 14:52
@azoellner
Copy link
Member Author

azoellner commented Mar 2, 2026

Hint: Probably the code of OCA/server-tools#3487 needs to be adapted accordingly as well:

-             ctx = (
-                 odoo.api.Environment(cr, uid, {})["res.users"]
-                 .with_context(prefetch_fields=False)
-                 .context_get()
-             )
+             ctx_prefetch = {"prefetch_fields": False}
+             ctx = odoo.api.Environment(cr, uid, ctx_prefetch)["res.users"].context_get()
+             ctx = dict(ctx)
+             ctx.update(ctx_prefetch)

@fkantelberg fkantelberg merged commit f562a2d into master Mar 5, 2026
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants