From 9dcbe33366b3735aa239816662ebc07e84691376 Mon Sep 17 00:00:00 2001 From: Denis Leemann Date: Mon, 15 Dec 2025 15:17:47 +0100 Subject: [PATCH] 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 1d48ab6..6af0440 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 e468669..1997842 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 efd6c82..becfbd5 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 e995ce6..a3eaa1a 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 @@ class RedisSessionStore(SessionStore): "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 @@ class RedisSessionStore(SessionStore): 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 @@ class RedisSessionStore(SessionStore): 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 @@ class RedisSessionStore(SessionStore): """ 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 @@ class RedisSessionStore(SessionStore): 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 @@ class RedisSessionStore(SessionStore): """ 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: