Skip to content

Conversation

@SirPyTech
Copy link

Without this change, longpolling requests always fail with error:

psycopg2.OperationalError: Unable to use a closed cursor.

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: 1

During 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:

This method can typically be used to check if we are in the frontend.

@SirPyTech SirPyTech force-pushed the 14.0-fix-website_require_login-closed_cursor branch from eb58787 to 64077be Compare January 21, 2026 16:51
@SirPyTech SirPyTech changed the title [FIX] website_require_login: Only filter website requests [FIX] website_require_login: Only redirect website requests Jan 21, 2026
@SirPyTech SirPyTech marked this pull request as ready for review January 21, 2026 16:53
Copy link
Contributor

@francesco-ooops francesco-ooops left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functional ok!

Copy link

@GSLabIt GSLabIt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@francesco-ooops
Copy link
Contributor

@OCA/website-maintainers good to go?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants