Skip to content

Commit

Permalink
[FIX] webservice: WARNING message in logs
Browse files Browse the repository at this point in the history
The use of a compute method on `oauth2_flow` when this field is touched by
the server environment mixin causes it to be defined twice as computed,
with differents settings, and this ultimately causes a warning message
in the logs:

```
WARNING odoo odoo.modules.registry: webservice.backend: inconsistent 'compute_sudo' for computed fields: protocol, url, auth_type, username, password, api_key, api_key_header, oauth2_flow, oauth2_clientid, oauth2_client_secret, oauth2_token_url, oauth2_authorization_url, oauth2_audience, oauth2_scope, content_type
```

We fix this by using an old fashioned onchange declaration on the
`auth_type` field.
  • Loading branch information
gurneyalex authored and SilvioC2C committed Jul 11, 2024
1 parent 532fb17 commit 3be2570
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions webservice/models/webservice_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class WebserviceBackend(models.Model):
],
readonly=False,
store=True,
compute="_compute_oauth2_flow",
)
oauth2_clientid = fields.Char(string="Client ID", auth_type="oauth2")
oauth2_client_secret = fields.Char(string="Client Secret", auth_type="oauth2")
Expand Down Expand Up @@ -121,8 +120,10 @@ def _get_adapter_protocol(self):
protocol += f"+{self.auth_type}-{self.oauth2_flow}"
return protocol

@api.depends("auth_type")
def _compute_oauth2_flow(self):
@api.onchange("auth_type")
def _onchange_oauth2_auth_type(self):
# reset the auth2_flow when auth_type is not oaut2
# using a compute method interfers with the server environment mixin
for rec in self:
if rec.auth_type != "oauth2":
rec.oauth2_flow = False
Expand Down

0 comments on commit 3be2570

Please sign in to comment.