Skip to content

[16.0][FIX]base: avoid invalid access error in onchange() when editing user #1294

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

Open
wants to merge 2 commits into
base: 16.0
Choose a base branch
from

Conversation

quirino95
Copy link

@quirino95 quirino95 commented Apr 22, 2025

Cherry-picked two fixes that avoid Access Error because can't read some fields on the employee that corresponds to the user.

Original PR:
odoo#148997

There was a refactor of class Form between 16.0 and 17.0 versions. The class moved from tests/common.py (16.0) to tests/form.py (17.0), so I just copied the two lines of the fix in _init_from_values method.

… user

Steps to reproduce:
-------------------
- install the "hr" module;
- remove access rights for "Employees";
- change language on the user profile.

Issue:
------
There's an Access Error because we can't read the `private_street` field
on the employee that corresponds to the user.

Cause:
------
The new version of onchange fetches the record values on the server side,
unlike the old version which used the values in the view.

In the old version, as we were using view values, this didn't cause any problems,
as the values came from a read that which took into account `SELF_READABLE_FIELDS`.

Note:
We do not have access to the value of the `private_street` field because it is a
related field with the attribute `related_sudo=False` and we do not have
access rights for the `hr.employee` model.

Solution:
---------
Use the cache and place the values of the fields in `SELF_READABLE_FIELDS` in it
before performing the onchange logic.

opw-3664929
@quirino95 quirino95 marked this pull request as draft April 22, 2025 15:26
When the server-side form view reads its record, the call to web_read()
leaves data in cache, which may prevent some access error to be
triggered in the first call to onchange().  In order to avoid that,
simply clean up the environment like after the other method calls.
@quirino95 quirino95 force-pushed the 16.0_onchange_no_access_fields_issue branch from 6850e8a to 7c21777 Compare April 22, 2025 15:31
@quirino95 quirino95 marked this pull request as ready for review April 22, 2025 15:34
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.

3 participants