[FIX] website_require_login: Only redirect website requests #1160
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Without this change, longpolling requests always fail with error:
Stack trace
2026-01-21 15:41:59,208 1 INFO db werkzeug: 172.19.0.7 - - [21/Jan/2026 15:41:59] "POST /longpolling/poll HTTP/1.1" 500 - 37 0.157 1.745 Traceback (most recent call last): File "/opt/odoo/custom/src/odoo/odoo/api.py", line 799, in get return field_cache[record._ids[0]] KeyError: 1During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/odoo/custom/src/odoo/odoo/fields.py", line 993, in get
value = env.cache.get(record, self)
File "/opt/odoo/custom/src/odoo/odoo/api.py", line 802, in get
raise CacheMiss(record, field)
odoo.exceptions.CacheMiss: 'website(1,).user_id'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/odoo/custom/src/odoo/odoo/service/wsgi_server.py", line 113, in application
return application_unproxied(environ, start_response)
File "/opt/odoo/custom/src/odoo/odoo/service/wsgi_server.py", line 88, in application_unproxied
result = odoo.http.root(environ, start_response)
File "/opt/odoo/custom/src/odoo/odoo/http.py", line 1298, in call
return self.dispatch(environ, start_response)
File "/opt/odoo/custom/src/odoo/odoo/http.py", line 1264, in call
return self.app(environ, start_wrapped)
File "/usr/local/lib/python3.8/site-packages/werkzeug/middleware/shared_data.py", line 220, in call
return self.app(environ, start_response)
File "/opt/odoo/custom/src/odoo/odoo/http.py", line 1489, in dispatch
result = ir_http._dispatch()
File "/opt/odoo/custom/src/odoo/addons/website_sale/models/ir_http.py", line 15, in _dispatch
return super(IrHttp, cls)._dispatch()
File "/opt/odoo/custom/src/website/website_require_login/models/ir_http.py", line 29, in _dispatch
user = website.user_id
File "/opt/odoo/custom/src/odoo/odoo/fields.py", line 2493, in get
return super().get(records, owner)
File "/opt/odoo/custom/src/odoo/odoo/fields.py", line 1019, in get
recs._fetch_field(self)
File "/opt/odoo/custom/src/odoo/odoo/models.py", line 3078, in _fetch_field
self._read(fnames)
File "/opt/odoo/custom/src/odoo/odoo/models.py", line 3145, in _read
cr.execute(query_str, params + [sub_ids])
File "", line 2, in execute
File "/opt/odoo/custom/src/odoo/odoo/sql_db.py", line 100, in check
raise psycopg2.OperationalError('Unable to use a closed cursor.')
psycopg2.OperationalError: Unable to use a closed cursor.
This module was also interfering with bus messages (like the ones from
web_notify) and prevented them from being shown.The called function
get_request_website(https://github.com/odoo/odoo/blob/cc0060e889603eb2e47fa44a8a22a70d7d784185/addons/website/models/ir_http.py#L43) exists with the exact purpose to identify when a request is coming from the website or not, from its docstring: