-
-
Notifications
You must be signed in to change notification settings - Fork 200
[19.0][FWP] server_environment: Preserve not env managed data #288
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5f4a582
[IMP] server_environment: Preserve not env managed data
qgroulard c025687
[FIX] mail_environment: Add migration script for field "smtp_authenti…
qgroulard 61d2b70
[FIX] server_environment: _preserve_not_env_managed_data
simahawk 27d60b4
[IMP] server_environment: add tests for _preserve_not_env_managed_data
simahawk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Copyright 2026 ACSONE SA/NV | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| from openupgradelib import openupgrade | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| env["ir.mail_server"]._preserve_not_env_managed_data(["smtp_authentication"]) | ||
|
yankinmax marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| from . import test_server_environment | ||
| from . import test_server_environment_config | ||
| from . import test_environment_variable | ||
| from . import test_preserve_not_env_managed_data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
| from odoo import api, models | ||
|
|
||
| # pylint: disable=consider-merging-classes-inherited | ||
|
|
||
|
|
||
| class FakePartner(models.Model): | ||
| _name = "res.partner" | ||
| _inherit = ["res.partner", "server.env.mixin"] | ||
|
|
||
| @property | ||
| def _server_env_fields(self): | ||
| base_fields = super()._server_env_fields | ||
| partner_fields = { | ||
| "city": {}, | ||
| } | ||
| partner_fields.update(base_fields) | ||
| return partner_fields | ||
|
|
||
| @api.model | ||
| def _server_env_global_section_name(self): | ||
| return "partner" |
87 changes: 87 additions & 0 deletions
87
server_environment/tests/test_preserve_not_env_managed_data.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| # Copyright 2026 Camptocamp SA | ||
| # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) | ||
|
|
||
| from odoo.orm.model_classes import add_to_registry | ||
|
|
||
| from . import common | ||
|
|
||
|
|
||
| class TestPreserveNotEnvManagedData(common.ServerEnvironmentCase): | ||
| @classmethod | ||
| def setUpClass(cls): | ||
| super().setUpClass() | ||
| from .fake_models import FakePartner | ||
|
|
||
| add_to_registry(cls.registry, FakePartner) | ||
| cls.registry._setup_models__(cls.env.cr, ["res.partner"]) | ||
| cls.registry.init_models(cls.env.cr, ["res.partner"], {"models_to_check": True}) | ||
|
|
||
| def setUp(self): | ||
| super().setUp() | ||
| # Deliberately not setting "city" here: writing it would already | ||
| # populate x_city_env_default through the mixin's inverse method, | ||
| # which would defeat the "no default yet" scenario below. | ||
| self.partner = self.env["res.partner"].create({"name": "Test partner"}) | ||
|
|
||
| def _set_raw_city_column(self, value): | ||
| """Bypass the ORM to simulate a stale/orphaned raw column value. | ||
|
|
||
| Once a field is taken over by the mixin it becomes non-stored, so | ||
| the ORM never reads or writes its physical column again. The column | ||
| itself is never dropped though, so it can keep holding old data from | ||
| before the field became server-env managed. | ||
| """ | ||
| self.env.cr.execute( | ||
| "UPDATE res_partner SET city = %s WHERE id = %s", | ||
| (value, self.partner.id), | ||
| ) | ||
| self.partner.invalidate_recordset(["city"]) | ||
|
|
||
| def test_preserve_rescues_value_when_no_default_yet(self): | ||
| """Rescue the raw column value when there is no default yet. | ||
|
|
||
| First-time adoption: no default stored yet, so the raw column | ||
| value must be rescued into the new default field. | ||
| """ | ||
| self._set_raw_city_column("Legacy Raw City") | ||
| self.env["res.partner"]._preserve_not_env_managed_data(["city"]) | ||
| self.partner.invalidate_recordset() | ||
| self.assertEqual(self.partner.x_city_env_default, "Legacy Raw City") | ||
| self.assertEqual(self.partner.city, "Legacy Raw City") | ||
|
|
||
| def test_preserve_does_not_overwrite_existing_default(self): | ||
| """Do not overwrite a default value that is already set. | ||
|
|
||
| A default already set (e.g. because the field was already | ||
| server-env managed by another module before) must not be clobbered | ||
| by a stale raw column value. | ||
| """ | ||
| # Simulate the field having already been server-env managed: a | ||
| # legitimate, up to date default is already stored. | ||
| self.partner.write({"city": "Current Default City"}) | ||
| self.assertEqual(self.partner.x_city_env_default, "Current Default City") | ||
| # The underlying (now unused) raw column still holds ancient data | ||
| # from before the field became non-stored. | ||
| self._set_raw_city_column("Ancient Stale City") | ||
| self.env["res.partner"]._preserve_not_env_managed_data(["city"]) | ||
| self.partner.invalidate_recordset() | ||
| self.assertEqual(self.partner.x_city_env_default, "Current Default City") | ||
| self.assertEqual(self.partner.city, "Current Default City") | ||
|
|
||
| def test_preserve_ignores_unknown_column(self): | ||
| """Fields without a matching raw column are silently skipped.""" | ||
| # Must not raise even though the field name doesn't exist as a | ||
| # column on the table. | ||
| self.env["res.partner"]._preserve_not_env_managed_data(["field_not_a_column"]) | ||
|
|
||
| def test_preserve_does_not_leak_into_env_configured_field(self): | ||
| """Keep reading from the environment when a config key is defined. | ||
|
|
||
| When a config key is defined, the field must keep reading from | ||
| the environment, regardless of any raw column value. | ||
| """ | ||
| self._set_raw_city_column("Legacy Raw City") | ||
| with self.load_config(public="[partner]\ncity = From Env\n"): | ||
| self.env["res.partner"]._preserve_not_env_managed_data(["city"]) | ||
| self.partner.invalidate_recordset() | ||
| self.assertEqual(self.partner.city, "From Env") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.