From 90f87c263f015b9de50e9f46c875b960f7c5ff37 Mon Sep 17 00:00:00 2001 From: vrenaville Date: Tue, 23 Sep 2025 16:19:19 +0200 Subject: [PATCH 1/3] fix: enable module for 19.0 --- session_redis/__manifest__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/session_redis/__manifest__.py b/session_redis/__manifest__.py index de134274..d7207578 100644 --- a/session_redis/__manifest__.py +++ b/session_redis/__manifest__.py @@ -18,5 +18,5 @@ "python": ["redis"], }, "website": "https://github.com/camptocamp/odoo-cloud-platform", - "installable": False, + "installable": True, } From 9dcbe33366b3735aa239816662ebc07e84691376 Mon Sep 17 00:00:00 2001 From: Denis Leemann Date: Mon, 15 Dec 2025 15:17:47 +0100 Subject: [PATCH 2/3] run pre-commit --- .pre-commit-config.yaml | 1 - requirements.txt | 1 + session_redis/http.py | 5 ++--- session_redis/session.py | 25 +++++++++++++++---------- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1d48ab6f..6af04403 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,7 +7,6 @@ exclude: | ^monitoring_prometheus/| ^monitoring_statsd/| ^monitoring_status/| - ^session_redis/| ^test_base_fileurl_field/| # END NOT INSTALLABLE ADDONS # Files and folders generated by bots, to avoid loops diff --git a/requirements.txt b/requirements.txt index e4686695..1997842f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ # generated from manifests external_dependencies python-json-logger +redis diff --git a/session_redis/http.py b/session_redis/http.py index efd6c827..becfbd58 100644 --- a/session_redis/http.py +++ b/session_redis/http.py @@ -93,15 +93,14 @@ def purge_fs_sessions(path): if is_true(os.getenv("ODOO_SESSION_REDIS")): if sentinel_host: _logger.debug( - "HTTP sessions stored in Redis with prefix '%s'. " - "Using Sentinel on %s:%s", + "HTTP sessions stored in Redis with prefix '%s'. Using Sentinel on %s:%s", prefix or "", sentinel_host, sentinel_port, ) else: _logger.debug( - "HTTP sessions stored in Redis with prefix '%s' on " "%s:%s", + "HTTP sessions stored in Redis with prefix '%s' on %s:%s", prefix or "", host, port, diff --git a/session_redis/session.py b/session_redis/session.py index e995ce69..a3eaa1aa 100644 --- a/session_redis/session.py +++ b/session_redis/session.py @@ -1,9 +1,10 @@ # Copyright 2016-2024 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) +import builtins import json import logging -from typing import TypeAlias, List +from typing import TypeAlias import odoo.http from odoo.http import SESSION_LIFETIME @@ -96,7 +97,7 @@ def save(self, session): "utf-8" ) if self.redis.set(key, data): - if type(expiration) != int: + if not isinstance(expiration, int): expiration = DEFAULT_SESSION_TIMEOUT_ANONYMOUS if expiration == 0: expiration = DEFAULT_SESSION_TIMEOUT_ANONYMOUS @@ -110,8 +111,7 @@ def delete(self, session): def get(self, sid): if not self.is_valid_key(sid): _logger.debug( - f"session with invalid sid '{sid}' has been asked, " - "returning a new one" + f"session with invalid sid '{sid}' has been asked, returning a new one" ) return self.new() @@ -134,7 +134,7 @@ def get(self, sid): return self.session_class(data, sid, False) def list(self): - keys = self.redis.keys("%s*" % self.prefix) + keys = self.redis.keys(f"{self.prefix}*") _logger.debug("a listing redis keys has been called") return [key[len(self.prefix) :] for key in keys] @@ -162,7 +162,9 @@ def delete_old_sessions(self, session): """ return - def get_missing_session_identifiers(self, identifiers: List[PartialSid]) -> set[PartialSid]: + def get_missing_session_identifiers( + self, identifiers: builtins.list[PartialSid] + ) -> set[PartialSid]: """ Given a list of partial session ids, return a set of those session ids which no longer exist in the keystore. @@ -188,7 +190,7 @@ def get_missing_session_identifiers(self, identifiers: List[PartialSid]) -> set[ return not_found - def delete_from_identifiers(self, identifiers: List[PartialSid]): + def delete_from_identifiers(self, identifiers: builtins.list[PartialSid]): """ Given a list of partial session ids, remove any that are in the session store. @@ -198,10 +200,13 @@ def delete_from_identifiers(self, identifiers: List[PartialSid]): """ patterns_to_unlink = [] for identifier in identifiers: - # Avoid removing a session if it does not match an identifier. - # See this same comment in odoo.http.FileSessionStore.delete_from_identifiers. + # Avoid removing a session if it does not match an identifier. See this same + # comment in odoo.http.FileSessionStore.delete_from_identifiers. if not odoo.http._session_identifier_re.match(identifier): - raise ValueError("Identifier format incorrect, did you pass in a string instead of a list?") + raise ValueError( + "Identifier format incorrect, did you pass in a string instead ", + "of a list?", + ) patterns_to_unlink.append(f"{self.prefix}{identifier}*") keys_to_unlink = [] for pattern in patterns_to_unlink: From 7375585a5b2ecaad3a0a080ef6e3a57f79d24ce8 Mon Sep 17 00:00:00 2001 From: Denis Leemann Date: Mon, 15 Dec 2025 16:00:21 +0100 Subject: [PATCH 3/3] Update session_redis/session.py Co-authored-by: Florent Xicluna <142113+florentx@users.noreply.github.com> --- session_redis/session.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/session_redis/session.py b/session_redis/session.py index a3eaa1aa..da356479 100644 --- a/session_redis/session.py +++ b/session_redis/session.py @@ -97,9 +97,8 @@ def save(self, session): "utf-8" ) if self.redis.set(key, data): - if not isinstance(expiration, int): + if not (expiration and isinstance(expiration, int)): expiration = DEFAULT_SESSION_TIMEOUT_ANONYMOUS - if expiration == 0: expiration = DEFAULT_SESSION_TIMEOUT_ANONYMOUS return self.redis.expire(key, expiration)