Since the refactoring of website.visitor with [1] (upsert), the
`access_token` is supposed to be holding the same value as the
`partner_id` when the visitor is linked to a partner:
- Anonymous visitor: no `partner_id`, `access_token` is a hash value
- Partner visitor: `partner_id` set, `access_token` should be sync with
`partner_id`.
`partner_id` is just a stored computed field holding the `access_token`
value if it is an integer value.
There should never be a case where there is a `partner_id` set and the
`access_token` is not equal to the `partner_id`.
For instance, having a visitor with `partner_id` = 4 and `access_token`
= `e4r3ejkj4` is supposed to be impossible.
It would lead to crash, because the visitor is only searched based on
his `access_token`, meaning that when searching for the visitor of
partner 4, none would be found and a new one would try to be created,
raising the `uniq_access_token_id` SQL constraint.
While the `partner_id`/`access_token` sync might seems weird, it is done
to allow the `upsert` use in SQL to improve perfs of this low level
behavior.
It's actually not as weak as it seems as there is only a single entry
point to update the `partner_id` and `access_token`: the authenticate
override of website.
Those fields are not supposed to be changed elsewhere.
Note that modifying the `access_token` would not be an issue as the
`partner_id` is just a stored compute based on the `access_token`.
But it's only true when modifying through the ORM as if you do that in
raw SQL, it won't go through the `api.depends` which is supposed to
recompute the stored computed `partner_id` field.
But something was forgotten during the initial dev: the partner merge
behavior: it does (on top of other thing) auto discover the m2o field
relations that points to a `res.partner` and modify those values in raw
SQL to the new value.
This is obviously wrong regarding the `website.visitor`'s `partner_id`
field, the `access_token` should also be updated, or when possible
visitors should be merged too.
Note that for DB upgrated from previous version to Odoo 16, this is
ensured through the following upgrade script [2]:
```sql
UPDATE website_visitor
SET access_token = partner_id::text
WHERE partner_id IS NOT NULL
```
[1]: https://github.com/odoo/odoo/commit/d348bed1ad9d3d16b295f013f015706be6c07820
[2]: https://github.com/odoo/upgrade/commit/0cedcbf70494dfeddeb5a97c13bf875cb6a86886
task-3148111
closes odoo/odoo#111002
X-original-commit: a87b4142dd4a2c05e3e1885b2c54f5e0d3c7ac47
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
33 lines
887 B
Python
33 lines
887 B
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from . import assets
|
|
from . import base_partner_merge
|
|
from . import ir_actions_server
|
|
from . import ir_asset
|
|
from . import ir_attachment
|
|
from . import ir_binary
|
|
from . import ir_http
|
|
from . import ir_model
|
|
from . import ir_model_data
|
|
from . import ir_module_module
|
|
from . import ir_qweb
|
|
from . import ir_qweb_fields
|
|
from . import mixins
|
|
from . import website
|
|
from . import website_menu
|
|
from . import website_page
|
|
from . import website_rewrite
|
|
from . import ir_rule
|
|
from . import ir_ui_view
|
|
from . import res_company
|
|
from . import res_partner
|
|
from . import res_users
|
|
from . import res_config_settings
|
|
from . import res_lang
|
|
from . import theme_models
|
|
from . import website_configurator_feature
|
|
from . import website_form
|
|
from . import website_snippet_filter
|
|
from . import website_visitor
|