Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# generated from manifests external_dependencies
python-json-logger
redis
2 changes: 1 addition & 1 deletion session_redis/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
"python": ["redis"],
},
"website": "https://github.com/camptocamp/odoo-cloud-platform",
"installable": False,
"installable": True,
}
5 changes: 2 additions & 3 deletions session_redis/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 15 additions & 11 deletions session_redis/session.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -96,9 +97,8 @@ def save(self, session):
"utf-8"
)
if self.redis.set(key, data):
if type(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)

Expand All @@ -110,8 +110,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()

Expand All @@ -134,7 +133,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]

Expand Down Expand Up @@ -162,7 +161,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.
Expand All @@ -188,7 +189,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.

Expand All @@ -198,10 +199,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:
Expand Down