Skip to content

[18.0][IMP] server_environment: Preserve not env managed data#264

Open
qgroulard wants to merge 2 commits intoOCA:18.0from
acsone:18.0-server_env_preserve_data-qgr
Open

[18.0][IMP] server_environment: Preserve not env managed data#264
qgroulard wants to merge 2 commits intoOCA:18.0from
acsone:18.0-server_env_preserve_data-qgr

Conversation

@qgroulard
Copy link
Copy Markdown
Contributor

Heavily inspired from #219, thank you @rven for your contribution.

I wanted to make @rven script more generic because this problem potentially happens every time we add the server.env.mixin to a model or when we add fields to the _server_env_fields() list.


Helper function typically used for hooks and migration scripts.
Restores database values for fields transitioning to 'server env managed'.

When a field is defined as managed by the server environment, Odoo ignores the value stored in the database, prioritizing the environment configuration instead. If no environment configuration exists, the field may effectively lose its previous value.

This method forces to 'persist' these values if they are not explicitly overridden by the current environment configuration.

@qgroulard qgroulard force-pushed the 18.0-server_env_preserve_data-qgr branch from 65f05d6 to f772104 Compare April 2, 2026 10:07
@qgroulard qgroulard marked this pull request as ready for review April 2, 2026 10:09
return

@api.model
def preserve_not_env_managed_data(self):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def preserve_not_env_managed_data(self):
def _preserve_not_env_managed_data(self):

If this is to be used in migration scripts, maybe it's safer to pass the list of fields/columns to handle explicitly?

@qgroulard qgroulard force-pushed the 18.0-server_env_preserve_data-qgr branch from f772104 to 51885bd Compare April 2, 2026 13:06
Helper function typically used for hooks and migration scripts.
Restores database values for fields transitioning to 'server env managed'.

When a field is defined as managed by the server environment, Odoo
ignores the value stored in the database, prioritizing the environment
configuration instead. If no environment configuration exists, the field
may effectively lose its previous value.

This method forces to 'persist' these values if they are not
explicitly overridden by the current environment configuration.
@qgroulard qgroulard force-pushed the 18.0-server_env_preserve_data-qgr branch from 51885bd to 7bec03f Compare April 2, 2026 13:07
…cation"

To preserve the value of field "smtp_authentication" if we don't set it from
the environment.
Which may happen to anyone updating the sources of mail_environment for its project.
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