[FIX] website: ensure request.env and env.uid are set

Some cases might lead to undefined `env` on request or undefined `uid`
on request.env:
1. Mobile app: no uid is set on the jsonRequest env
2. Multi db: _env is None on request, and request.env unbound

1. Was checked with [1]
2. Was checked with [2] but by doing so, it actually broke the check
   done for 1.

[1]: https://github.com/odoo/odoo/commit/245ef4b0fddc7e5da3ebe841438c2d2902933f14
[2]: https://github.com/odoo/odoo/commit/3a7033463ea98def2e3fb85333c4f00f7c7d6925

task-2867045

Part-of: odoo/odoo#87857
This commit is contained in:
Romain Derie
2022-06-07 16:31:19 +02:00
parent 124c65b6a1
commit 92feb6a67f
+1 -1
View File
@@ -182,7 +182,7 @@ class WebsiteVisitor(models.Model):
# This function can be called in json with mobile app.
# In case of mobile app, no uid is set on the jsonRequest env.
# In case of multi db, _env is None on request, and request.env unbound.
if not request:
if not (request and request.env and request.env.uid):
return None
Visitor = self.env['website.visitor'].sudo()
visitor = Visitor