Skip to content

[18.0][FIX] server_environment: object has no attribute _compute_server_env - #319

Open
sebalix wants to merge 1 commit into
OCA:18.0from
akretion:18.0-fix-server_environment-shared_field_description
Open

sebalix wants to merge 1 commit into
OCA:18.0from
akretion:18.0-fix-server_environment-shared_field_description

Conversation

@sebalix

@sebalix sebalix commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Build a new field descriptor instead of mutating the existing one that could be shared.

Issue #301

In my case it's happening during test builds. E.g. when running tests on cross_connect_client, or partner_firstname:

Traceback (most recent call last):
  File "/home/odoo/src/user/addons/oca/cross_connect_client/tests/test_cross_connect_client.py", line 260, in test_act_url_redirect
    user = self.env["res.users"].create(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<decorator-gen-34>", line 2, in create
  File "/home/odoo/src/odoo/odoo/api.py", line 497, in _model_create_multi
    return create(self, [arg])
           ^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/odoo/addons/base/models/res_users.py", line 1906, in create
    users = super(UsersView, self).create(new_vals_list)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<decorator-gen-32>", line 2, in create
  File "/home/odoo/src/odoo/odoo/api.py", line 498, in _model_create_multi
    return create(self, arg)
           ^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/odoo/addons/base/models/res_users.py", line 1604, in create
    return super(UsersImplied, self).create(vals_list)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<decorator-gen-30>", line 2, in create
  File "/home/odoo/src/odoo/odoo/api.py", line 498, in _model_create_multi
    return create(self, arg)
           ^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/odoo/addons/base/models/res_users.py", line 705, in create
    users = super(Users, self).create(vals_list)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<decorator-gen-0>", line 2, in create
  File "/home/odoo/src/odoo/odoo/api.py", line 498, in _model_create_multi
    return create(self, arg)
           ^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/odoo/models.py", line 5044, in create
    parents = self.env[model_name].create([
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<decorator-gen-24>", line 2, in create
  File "/home/odoo/src/odoo/odoo/api.py", line 498, in _model_create_multi
    return create(self, arg)
           ^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/odoo/addons/base/models/res_partner.py", line 828, in create
    partner._handle_first_contact_creation()
  File "/home/odoo/src/odoo/odoo/addons/base/models/res_partner.py", line 723, in _handle_first_contact_creation
    and any(self[f] for f in address_fields)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/odoo/addons/base/models/res_partner.py", line 723, in <genexpr>
    and any(self[f] for f in address_fields)
            ~~~~^^^
  File "/home/odoo/src/odoo/odoo/models.py", line 7096, in __getitem__
    return self._fields[key].__get__(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/odoo/src/odoo/odoo/fields.py", line 1309, in __get__
    self.compute_value(recs)
  File "/home/odoo/src/odoo/odoo/fields.py", line 1491, in compute_value
    records._compute_field_value(self)
  File "/home/odoo/src/odoo/odoo/models.py", line 5315, in _compute_field_value
    fields.determine(field.compute, self)
  File "/home/odoo/src/odoo/odoo/fields.py", line 108, in determine
    needle = getattr(records, needle)
             ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'res.partner' object has no attribute '_compute_server_env'

There is still some black magic to me why it happens, but creating a whole new field descriptor instead of updating the existing one should be safer.

Build a new field descriptor instead of mutating the existing one that
could be shared.
@OCA-git-bot OCA-git-bot added series:18.0 mod:server_environment Module server_environment labels Nov 9, 2026
@sebalix
sebalix marked this pull request as ready for review November 9, 2026 15:20
@sebalix sebalix changed the title [18.0][FIX] server_environment: object has no attribute '_compute_server_env' [18.0][FIX] server_environment: object has no attribute _compute_server_env Nov 10, 2026
@prashantpag26

Copy link
Copy Markdown

This addresses #301 and the approach seems sound. Since it changes how the field descriptor is registered, could you add a regression test that reproduces #301, for example creating a res.users in a test class that inherits the mixin? Otherwise it's hard to tell whether a later refactor reintroduces it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:server_environment Module server_environment series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants