[FIX] web: filter cached inaccessible x2many records in web_read - #257517
[FIX] web: filter cached inaccessible x2many records in web_read#257517fw-bot wants to merge 1 commit into
Conversation
|
This PR targets 18.0 and is part of the forward-port chain. Further PRs will be created up to master. More info at https://github.com/odoo/odoo/wiki/Mergebot#forward-port |
| co_records = co_records.with_context(active_test=False).search( | ||
| [('id', 'in', co_records.ids)], order=field_spec['order'], | ||
| [('id', 'in', co_records.ids)], order=field_spec_order, | ||
| ).with_context(co_records.env.context) # Reapply previous context |
There was a problem hiding this comment.
@cro-odoo the failing tests may be because this call to search() crashes. I suggest to wrap it into a try/except, so that some AccessError turns co_records into an empty recordset. That's the behavior we now have in master.
d06ddc4 to
6f29334
Compare
6f29334 to
b760be6
Compare
|
hello @rco-odoo |
b760be6 to
05ded3e
Compare
|
Hello future reviewer, I adjusted the previous patch "a bit more" after investigating the failed tests. The original bug is still cache pollution: "web_read" may reuse inaccessible x2many ids and should not expose or crash on them. Here is the new logic to remove polluted x2many values:
So to filter, we use _filtered_access('read') (to be changed to clear_access_cache in 19.1 #250904 (comment)) but using it without checking if the user has access to the model introduces a regression in hr_appraisal app (see TestHrAppraisalRequestUi.test_send_appraisal_request_by_email_flow)
So my idea is to only apply _filtered_access('read') in the fields section when the user has general read access on the comodel, otherwise co-records keep the relation ids unchanged. This is a bigger patch than the first version, so I would like your feedback @rco-odoo or @kmagusiak on this PR: Is still this look ok for you ? Since you have a more global view on the ORM methods / behaviors. |
|
Before deciding, let's see future issues. If that changes the behaviour too much, I would opt to revert the change in 17.0 and abandon that change as too risky. |
|
Not waiting for CI to create followup forward-ports. |
closes #257517 Signed-off-by: Raphael Collet <rco@odoo.com> Signed-off-by: Krzysztof Magusiak (krma) <krma@odoo.com>
closes odoo#257517 Signed-off-by: Raphael Collet <rco@odoo.com> Signed-off-by: Krzysztof Magusiak (krma) <krma@odoo.com>
closes odoo/odoo#257517 Signed-off-by: Raphael Collet <rco@odoo.com> Signed-off-by: Krzysztof Magusiak (krma) <krma@odoo.com>

Description of the issue/feature this PR addresses:
web_read on x2many fields can reuse cached ids after write/web_save. Some of these cached ids may be inaccessible with the current record rules/context (cache pollution).
Example:
Context:
Steps:
Current behavior before PR (without fix):
After saving a form with an x2many field, web_save calls write and then web_read. In this flow, web_read can include inaccessible x2many ids from cache and raise an AccessError.
Desired behavior after PR is merged:
x2many records are re-filtered with current read rules before formatting, and inaccessible ids are removed from values_list.
Forward-Port-Of: #250904