run pre-commit

This commit is contained in:
Denis Leemann
2025-12-15 15:34:26 +01:00
parent 90f87c263f
commit 9dcbe33366
4 changed files with 18 additions and 14 deletions
-1
View File
@@ -7,7 +7,6 @@ exclude: |
^monitoring_prometheus/| ^monitoring_prometheus/|
^monitoring_statsd/| ^monitoring_statsd/|
^monitoring_status/| ^monitoring_status/|
^session_redis/|
^test_base_fileurl_field/| ^test_base_fileurl_field/|
# END NOT INSTALLABLE ADDONS # END NOT INSTALLABLE ADDONS
# Files and folders generated by bots, to avoid loops # Files and folders generated by bots, to avoid loops
+1
View File
@@ -1,2 +1,3 @@
# generated from manifests external_dependencies # generated from manifests external_dependencies
python-json-logger python-json-logger
redis
+2 -3
View File
@@ -93,15 +93,14 @@ def purge_fs_sessions(path):
if is_true(os.getenv("ODOO_SESSION_REDIS")): if is_true(os.getenv("ODOO_SESSION_REDIS")):
if sentinel_host: if sentinel_host:
_logger.debug( _logger.debug(
"HTTP sessions stored in Redis with prefix '%s'. " "HTTP sessions stored in Redis with prefix '%s'. Using Sentinel on %s:%s",
"Using Sentinel on %s:%s",
prefix or "", prefix or "",
sentinel_host, sentinel_host,
sentinel_port, sentinel_port,
) )
else: else:
_logger.debug( _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 "", prefix or "",
host, host,
port, port,
+15 -10
View File
@@ -1,9 +1,10 @@
# Copyright 2016-2024 Camptocamp SA # Copyright 2016-2024 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
import builtins
import json import json
import logging import logging
from typing import TypeAlias, List from typing import TypeAlias
import odoo.http import odoo.http
from odoo.http import SESSION_LIFETIME from odoo.http import SESSION_LIFETIME
@@ -96,7 +97,7 @@ class RedisSessionStore(SessionStore):
"utf-8" "utf-8"
) )
if self.redis.set(key, data): if self.redis.set(key, data):
if type(expiration) != int: if not isinstance(expiration, int):
expiration = DEFAULT_SESSION_TIMEOUT_ANONYMOUS expiration = DEFAULT_SESSION_TIMEOUT_ANONYMOUS
if expiration == 0: if expiration == 0:
expiration = DEFAULT_SESSION_TIMEOUT_ANONYMOUS expiration = DEFAULT_SESSION_TIMEOUT_ANONYMOUS
@@ -110,8 +111,7 @@ class RedisSessionStore(SessionStore):
def get(self, sid): def get(self, sid):
if not self.is_valid_key(sid): if not self.is_valid_key(sid):
_logger.debug( _logger.debug(
f"session with invalid sid '{sid}' has been asked, " f"session with invalid sid '{sid}' has been asked, returning a new one"
"returning a new one"
) )
return self.new() return self.new()
@@ -134,7 +134,7 @@ class RedisSessionStore(SessionStore):
return self.session_class(data, sid, False) return self.session_class(data, sid, False)
def list(self): 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") _logger.debug("a listing redis keys has been called")
return [key[len(self.prefix) :] for key in keys] return [key[len(self.prefix) :] for key in keys]
@@ -162,7 +162,9 @@ class RedisSessionStore(SessionStore):
""" """
return 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 Given a list of partial session ids, return a set of those session ids
which no longer exist in the keystore. which no longer exist in the keystore.
@@ -188,7 +190,7 @@ class RedisSessionStore(SessionStore):
return not_found 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. 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 = [] patterns_to_unlink = []
for identifier in identifiers: for identifier in identifiers:
# Avoid removing a session if it does not match an identifier. # Avoid removing a session if it does not match an identifier. See this same
# See this same comment in odoo.http.FileSessionStore.delete_from_identifiers. # comment in odoo.http.FileSessionStore.delete_from_identifiers.
if not odoo.http._session_identifier_re.match(identifier): 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}*") patterns_to_unlink.append(f"{self.prefix}{identifier}*")
keys_to_unlink = [] keys_to_unlink = []
for pattern in patterns_to_unlink: for pattern in patterns_to_unlink: