Script 'mail_helper' called by obssrc
Hello community,
here is the log from the commit of package python-py-key-value-aio for
openSUSE:Factory checked in at 2026-11-19 16:54:55
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-py-key-value-aio (Old)
and /work/SRC/openSUSE:Factory/.python-py-key-value-aio.new.1251 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-py-key-value-aio"
Thu Nov 19 16:54:55 2026 rev:3 rq:1398534 version:0.5.0
Changes:
--------
---
/work/SRC/openSUSE:Factory/python-py-key-value-aio/python-py-key-value-aio.changes
2026-09-21 12:24:38.742868693 +0200
+++
/work/SRC/openSUSE:Factory/.python-py-key-value-aio.new.1251/python-py-key-value-aio.changes
2026-11-19 16:55:15.973167543 +0100
@@ -1,0 +2,15 @@
+Tue Nov 17 16:37:58 UTC 2026 - Martin Pluskal <[email protected]>
+
+- Update to 0.5.0:
+ * S3 and DynamoDB stores now use aiobotocore directly instead
+ of aioboto3
+ * Replace deprecated Redis SETEX writes, follow SCAN cursors
+ when enumerating keys, and fix Valkey/Memcached TTL handling
+ * Make lazy store setup safe across event loops; mark
+ AsyncKeyValue as runtime checkable for Python 3.15
+ * Preserve supplied caches and existing entries in local stores,
+ and routing, values and TTL contracts in wrappers/adapters
+ * Keep MultiDiskStore cache directories within the configured
+ base; export ManagedEntry
+
+-------------------------------------------------------------------
Old:
----
py_key_value_aio-0.4.6.tar.gz
New:
----
py_key_value_aio-0.5.0.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-py-key-value-aio.spec ++++++
--- /var/tmp/diff_new_pack.dLd6Ye/_old 2026-11-19 16:55:16.679197470 +0100
+++ /var/tmp/diff_new_pack.dLd6Ye/_new 2026-11-19 16:55:16.681197555 +0100
@@ -17,7 +17,7 @@
Name: python-py-key-value-aio
-Version: 0.4.6
+Version: 0.5.0
Release: 0
Summary: Async key-value store abstraction with multiple backends
License: Apache-2.0
++++++ py_key_value_aio-0.4.6.tar.gz -> py_key_value_aio-0.5.0.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/py_key_value_aio-0.4.6/PKG-INFO
new/py_key_value_aio-0.5.0/PKG-INFO
--- old/py_key_value_aio-0.4.6/PKG-INFO 1970-01-01 01:00:00.000000000 +0100
+++ new/py_key_value_aio-0.5.0/PKG-INFO 1970-01-01 01:00:00.000000000 +0100
@@ -1,6 +1,6 @@
Metadata-Version: 2.4
Name: py-key-value-aio
-Version: 0.4.6
+Version: 0.5.0
Summary: Async Key-Value Store - A pluggable interface for KV Stores
License-Expression: Apache-2.0
License-File: LICENSE
@@ -11,7 +11,10 @@
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
+Classifier: Programming Language :: Python :: 3.14
+Classifier: Programming Language :: Python :: 3.15
Requires-Dist: beartype>=0.20.0
+Requires-Dist: beartype>=0.23.0 ; python_full_version >= '3.15'
Requires-Dist: typing-extensions>=4.15.0
Requires-Dist: aerospike>=16.0.0 ; extra == 'aerospike'
Requires-Dist: azure-data-tables>=12.4.0 ; extra == 'azure-tables'
@@ -25,18 +28,17 @@
Requires-Dist: mkdocstrings-python>=1.10.0 ; extra == 'docs'
Requires-Dist: duckdb>=1.1.1 ; extra == 'duckdb'
Requires-Dist: pytz>=2025.2 ; extra == 'duckdb'
-Requires-Dist: aioboto3>=13.3.0 ; extra == 'dynamodb'
+Requires-Dist: types-aiobotocore-lite[aiobotocore]>=2.16.0 ; extra ==
'dynamodb'
Requires-Dist: types-aiobotocore-dynamodb>=2.16.0 ; extra == 'dynamodb'
Requires-Dist: elasticsearch>=8.0.0 ; extra == 'elasticsearch'
Requires-Dist: aiohttp>=3.12 ; extra == 'elasticsearch'
-Requires-Dist: aiofile>=3.5.0,!=3.9.0,<3.10 ; python_full_version < '3.11' and
extra == 'filetree'
+Requires-Dist: aiofile>=3.8.8,!=3.9.0,<3.10 ; python_full_version < '3.11' and
extra == 'filetree'
Requires-Dist: aiofile>=3.12.3 ; python_full_version >= '3.11' and extra ==
'filetree'
Requires-Dist: anyio>=4.4.0 ; extra == 'filetree'
Requires-Dist: google-cloud-firestore>=2.13.0 ; extra == 'firestore'
Requires-Dist: google-auth>=2.24.0 ; extra == 'firestore'
Requires-Dist: keyring>=25.6.0 ; extra == 'keyring'
Requires-Dist: keyring>=25.6.0 ; extra == 'keyring-linux'
-Requires-Dist: dbus-python>=1.4.0 ; extra == 'keyring-linux'
Requires-Dist: aiomcache>=0.8.0 ; extra == 'memcached'
Requires-Dist: cachetools>=5.0.0 ; extra == 'memory'
Requires-Dist: pymongo>=4.9.0 ; extra == 'mongodb'
@@ -44,9 +46,8 @@
Requires-Dist: asyncpg>=0.30.0 ; extra == 'postgresql'
Requires-Dist: pydantic>=2.11.9 ; extra == 'pydantic'
Requires-Dist: redis>=4.3.0 ; extra == 'redis'
-Requires-Dist: rocksdict>=0.3.24 ; python_full_version >= '3.12' and extra ==
'rocksdb'
-Requires-Dist: rocksdict>=0.3.2 ; python_full_version < '3.12' and extra ==
'rocksdb'
-Requires-Dist: aioboto3>=13.3.0 ; extra == 's3'
+Requires-Dist: rocksdict>=0.3.24 ; extra == 'rocksdb'
+Requires-Dist: types-aiobotocore-lite[aiobotocore]>=2.16.0 ; extra == 's3'
Requires-Dist: types-aiobotocore-s3>=2.16.0 ; extra == 's3'
Requires-Dist: valkey-glide>=2.1.0 ; extra == 'valkey'
Requires-Dist: hvac>=2.3.0 ; extra == 'vault'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/py_key_value_aio-0.4.6/pyproject.toml
new/py_key_value_aio-0.5.0/pyproject.toml
--- old/py_key_value_aio-0.4.6/pyproject.toml 1970-01-01 01:00:00.000000000
+0100
+++ new/py_key_value_aio-0.5.0/pyproject.toml 1970-01-01 01:00:00.000000000
+0100
@@ -1,6 +1,6 @@
[project]
name = "py-key-value-aio"
-version = "0.4.6"
+version = "0.5.0"
description = "Async Key-Value Store - A pluggable interface for KV Stores"
readme = "README.md"
requires-python = ">=3.10"
@@ -14,9 +14,12 @@
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
+ "Programming Language :: Python :: 3.14",
+ "Programming Language :: Python :: 3.15",
]
dependencies = [
"beartype>=0.20.0",
+ "beartype>=0.23.0; python_version >= '3.15'",
"typing-extensions>=4.15.0",
]
@@ -27,7 +30,7 @@
"pathvalidate>=3.3.1",
]
filetree = [
- "aiofile>=3.5.0,!=3.9.0,<3.10 ; python_version < '3.11'",
+ "aiofile>=3.8.8,!=3.9.0,<3.10 ; python_version < '3.11'",
"aiofile>=3.12.3 ; python_version >= '3.11'",
"anyio>=4.4.0",
]
@@ -45,11 +48,11 @@
]
opensearch = ["opensearch-py[async]>=2.0.0"]
dynamodb = [
- "aioboto3>=13.3.0",
+ "types-aiobotocore-lite[aiobotocore]>=2.16.0",
"types-aiobotocore-dynamodb>=2.16.0",
]
s3 = [
- "aioboto3>=13.3.0",
+ "types-aiobotocore-lite[aiobotocore]>=2.16.0",
"types-aiobotocore-s3>=2.16.0",
]
azure-tables = [
@@ -57,16 +60,10 @@
"azure-core>=1.29.0",
]
keyring = ["keyring>=25.6.0"]
-keyring-linux = [
- "keyring>=25.6.0",
- "dbus-python>=1.4.0",
-]
+keyring-linux = ["keyring>=25.6.0"]
pydantic = ["pydantic>=2.11.9"]
aerospike = ["aerospike>=16.0.0"]
-rocksdb = [
- "rocksdict>=0.3.24 ; python_version >= '3.12'",
- "rocksdict>=0.3.2 ; python_version < '3.12'",
-]
+rocksdb = ["rocksdict>=0.3.24"]
duckdb = [
"duckdb>=1.1.1",
"pytz>=2025.2",
@@ -186,10 +183,11 @@
[dependency-groups]
dev = [
-
"py-key-value-aio[memory,disk,filetree,redis,elasticsearch,opensearch,memcached,mongodb,vault,dynamodb,s3,azure-tables,rocksdb,duckdb,firestore,postgresql]",
- "py-key-value-aio[chdb]; platform_system != 'Windows'",
- "py-key-value-aio[valkey]; platform_system != 'Windows'",
- "py-key-value-aio[aerospike]; platform_system != 'Windows'",
+
"py-key-value-aio[memory,disk,filetree,redis,elasticsearch,opensearch,memcached,mongodb,vault,dynamodb,s3,azure-tables,duckdb,firestore,postgresql]",
+ "py-key-value-aio[chdb]; platform_system != 'Windows' and python_version <
'3.15'",
+ "py-key-value-aio[rocksdb]; python_version < '3.15'",
+ "py-key-value-aio[valkey]; platform_system != 'Windows' and python_version
< '3.15'",
+ "py-key-value-aio[aerospike]; platform_system != 'Windows' and
python_version < '3.15'",
"py-key-value-aio[keyring]",
"py-key-value-aio[pydantic]",
"py-key-value-aio[wrappers-encryption]",
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/py_key_value_aio-0.4.6/pyproject.toml.orig
new/py_key_value_aio-0.5.0/pyproject.toml.orig
--- old/py_key_value_aio-0.4.6/pyproject.toml.orig 1970-01-01
01:00:00.000000000 +0100
+++ new/py_key_value_aio-0.5.0/pyproject.toml.orig 1970-01-01
01:00:00.000000000 +0100
@@ -1,6 +1,6 @@
[project]
name = "py-key-value-aio"
-version = "0.4.6"
+version = "0.5.0"
description = "Async Key-Value Store - A pluggable interface for KV Stores"
readme = "README.md"
requires-python = ">=3.10"
@@ -14,9 +14,13 @@
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
+ "Programming Language :: Python :: 3.14",
+ "Programming Language :: Python :: 3.15",
]
dependencies = [
"beartype>=0.20.0",
+ # Older beartype releases fail to import on Python 3.15.
+ "beartype>=0.23.0; python_version >= '3.15'",
"typing-extensions>=4.15.0",
]
@@ -36,7 +40,7 @@
# Fixed upstream in 3.10.0+, but aiofile dropped Python 3.10 support in
that same release,
# so exclude the broken 3.9.0 and fall back to 3.8.8 (the next-newest
3.10-compatible release,
# which predates the broken metadata-reading code entirely) for Python
3.10.
- "aiofile>=3.5.0,!=3.9.0,<3.10 ; python_version < '3.11'",
+ "aiofile>=3.8.8,!=3.9.0,<3.10 ; python_version < '3.11'",
"aiofile>=3.12.3 ; python_version >= '3.11'",
"anyio>=4.4.0",
]
@@ -47,17 +51,16 @@
memcached = ["aiomcache>=0.8.0"]
elasticsearch = ["elasticsearch>=8.0.0", "aiohttp>=3.12"]
opensearch = ["opensearch-py[async]>=2.0.0"]
-dynamodb = ["aioboto3>=13.3.0", "types-aiobotocore-dynamodb>=2.16.0"]
-s3 = ["aioboto3>=13.3.0", "types-aiobotocore-s3>=2.16.0"]
+dynamodb = ["types-aiobotocore-lite[aiobotocore]>=2.16.0",
"types-aiobotocore-dynamodb>=2.16.0"]
+s3 = ["types-aiobotocore-lite[aiobotocore]>=2.16.0",
"types-aiobotocore-s3>=2.16.0"]
azure-tables = ["azure-data-tables>=12.4.0", "azure-core>=1.29.0"]
keyring = ["keyring>=25.6.0"]
-keyring-linux = ["keyring>=25.6.0", "dbus-python>=1.4.0"]
+# Kept as an alias of `keyring` for existing installs. It no longer pulls in
dbus-python, which
+# needs system D-Bus headers to build; keyring uses the pure-Python jeepney on
Linux instead.
+keyring-linux = ["keyring>=25.6.0"]
pydantic = ["pydantic>=2.11.9"]
aerospike = ["aerospike>=16.0.0"]
-rocksdb = [
- "rocksdict>=0.3.24 ; python_version >= '3.12'",
- "rocksdict>=0.3.2 ; python_version < '3.12'"
-]
+rocksdb = ["rocksdict>=0.3.24"]
duckdb = ["duckdb>=1.1.1", "pytz>=2025.2"]
chdb = ["chdb>=4.1.1"]
postgresql = ["asyncpg>=0.30.0"]
@@ -72,10 +75,12 @@
[dependency-groups]
dev = [
-
"py-key-value-aio[memory,disk,filetree,redis,elasticsearch,opensearch,memcached,mongodb,vault,dynamodb,s3,azure-tables,rocksdb,duckdb,firestore,postgresql]",
- "py-key-value-aio[chdb]; platform_system != 'Windows'",
- "py-key-value-aio[valkey]; platform_system != 'Windows'",
- "py-key-value-aio[aerospike]; platform_system != 'Windows'",
+
"py-key-value-aio[memory,disk,filetree,redis,elasticsearch,opensearch,memcached,mongodb,vault,dynamodb,s3,azure-tables,duckdb,firestore,postgresql]",
+ # chdb, rocksdict, valkey-glide and aerospike do not support Python 3.15
yet.
+ "py-key-value-aio[chdb]; platform_system != 'Windows' and python_version <
'3.15'",
+ "py-key-value-aio[rocksdb]; python_version < '3.15'",
+ "py-key-value-aio[valkey]; platform_system != 'Windows' and python_version
< '3.15'",
+ "py-key-value-aio[aerospike]; platform_system != 'Windows' and
python_version < '3.15'",
"py-key-value-aio[keyring]",
"py-key-value-aio[pydantic]",
"py-key-value-aio[wrappers-encryption]",
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/py_key_value_aio-0.4.6/src/key_value/aio/adapters/pydantic/base.py
new/py_key_value_aio-0.5.0/src/key_value/aio/adapters/pydantic/base.py
--- old/py_key_value_aio-0.4.6/src/key_value/aio/adapters/pydantic/base.py
1970-01-01 01:00:00.000000000 +0100
+++ new/py_key_value_aio-0.5.0/src/key_value/aio/adapters/pydantic/base.py
1970-01-01 01:00:00.000000000 +0100
@@ -260,9 +260,13 @@
return (None, None)
async def ttl_many(self, keys: Sequence[str], *, collection: str | None =
None) -> list[tuple[T | None, float | None]]:
- """Batch get models with TTLs. Each element is (model|None,
ttl_seconds|None)."""
+ """Batch get models with TTLs. Missing or invalid values return (None,
None), as in ttl()."""
collection = collection or self._default_collection
entries: list[tuple[dict[str, Any] | None, float | None]] = await
self._key_value.ttl_many(keys=keys, collection=collection)
- return [(self._validate_model(value=entry) if entry is not None else
None, ttl_info) for entry, ttl_info in entries]
+ results: list[tuple[T | None, float | None]] = []
+ for entry, ttl_info in entries:
+ model = self._validate_model(value=entry) if entry is not None
else None
+ results.append((model, ttl_info) if model is not None else (None,
None))
+ return results
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/py_key_value_aio-0.4.6/src/key_value/aio/protocols/key_value.py
new/py_key_value_aio-0.5.0/src/key_value/aio/protocols/key_value.py
--- old/py_key_value_aio-0.4.6/src/key_value/aio/protocols/key_value.py
1970-01-01 01:00:00.000000000 +0100
+++ new/py_key_value_aio-0.5.0/src/key_value/aio/protocols/key_value.py
1970-01-01 01:00:00.000000000 +0100
@@ -182,6 +182,7 @@
...
+@runtime_checkable
class AsyncKeyValue(AsyncKeyValueProtocol, Protocol):
"""A protocol for key-value store operations.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/py_key_value_aio-0.4.6/src/key_value/aio/stores/base.py
new/py_key_value_aio-0.5.0/src/key_value/aio/stores/base.py
--- old/py_key_value_aio-0.4.6/src/key_value/aio/stores/base.py 1970-01-01
01:00:00.000000000 +0100
+++ new/py_key_value_aio-0.5.0/src/key_value/aio/stores/base.py 1970-01-01
01:00:00.000000000 +0100
@@ -3,11 +3,13 @@
"""
from abc import ABC, abstractmethod
-from asyncio.locks import Lock
+from asyncio import shield, wrap_future
from collections import defaultdict
from collections.abc import Mapping, Sequence
+from concurrent.futures import Future
from contextlib import AsyncExitStack
from datetime import datetime
+from threading import Lock as ThreadLock
from types import MappingProxyType, TracebackType
from typing import Any, SupportsFloat
@@ -15,7 +17,7 @@
from key_value.aio._utils.beartype import bear_enforce
from key_value.aio._utils.constants import DEFAULT_COLLECTION_NAME
-from key_value.aio._utils.managed_entry import ManagedEntry
+from key_value.aio._utils.managed_entry import ManagedEntry as ManagedEntry #
public: used by custom BaseStore subclasses
from key_value.aio._utils.sanitization import PassthroughStrategy,
SanitizationStrategy
from key_value.aio._utils.serialization import BasicSerializationAdapter,
SerializationAdapter
from key_value.aio._utils.time_to_live import prepare_entry_timestamps
@@ -65,9 +67,10 @@
"""
_setup_complete: bool
- _setup_lock: Lock
+ _setup_future: Future[None] | None
+ _setup_state_lock: ThreadLock
- _setup_collection_locks: defaultdict[str, Lock]
+ _setup_collection_futures: dict[str, Future[None]]
_setup_collection_complete: defaultdict[str, bool]
_serialization_adapter: SerializationAdapter
@@ -104,8 +107,9 @@
"""
self._setup_complete = False
- self._setup_lock = Lock()
- self._setup_collection_locks = defaultdict(Lock)
+ self._setup_future = None
+ self._setup_state_lock = ThreadLock()
+ self._setup_collection_futures = {}
self._setup_collection_complete = defaultdict(bool)
self._seed = _seed_to_frozen_seed_data(seed=seed or {})
@@ -127,6 +131,9 @@
async def _setup(self) -> None:
"""Initialize the store (called once before first use)."""
+ async def _cleanup_failed_setup(self) -> None:
+ """Release resources owned by a failed setup attempt."""
+
async def _setup_collection(self, *, collection: str) -> None:
"""Initialize the collection (called once before first use of the
collection)."""
@@ -143,42 +150,95 @@
async def _seed_store(self) -> None:
"""Seed the store with the data from the seed."""
- for collection, items in self._seed.items():
- await self.setup_collection(collection=collection)
+ for seed_collection, items in self._seed.items():
+ collection = seed_collection or self.default_collection
+ with self._setup_state_lock:
+ collection_ready = self._setup_collection_complete[collection]
+ if not collection_ready:
+ await self._setup_collection(collection=collection)
+ with self._setup_state_lock:
+ self._setup_collection_complete[collection] = True
+
for key, value in items.items():
- await self.put(key=key, value=dict(value),
collection=collection)
+ created_at, _, expires_at = prepare_entry_timestamps(ttl=None)
+ await self._put_managed_entry(
+ key=key,
+ collection=collection,
+ managed_entry=ManagedEntry(value=dict(value),
created_at=created_at, expires_at=expires_at),
+ )
async def setup(self) -> None:
"""Initialize the store if not already initialized.
- This method is called automatically before any store operations and
uses a lock to ensure
- thread-safe lazy initialization. It can also be called manually to
ensure the store is ready
- before performing operations. The setup process includes calling the
`_setup()` hook and
- seeding the store with initial data if provided.
+ This method is called automatically before any store operations and
coordinates lazy
+ initialization across threads and event loops. The setup process
includes calling the
+ `_setup()` hook and seeding the store with initial data if provided.
This method is idempotent - calling it multiple times has no
additional effect after the first call.
"""
- if not self._setup_complete:
- async with self._setup_lock:
- if not self._setup_complete:
- try:
- await self._setup()
- except Exception as e:
- raise StoreSetupError(
- message=f"Failed to setup key value store: {e}",
extra_info={"store": self.__class__.__name__}
- ) from e
+ with self._setup_state_lock:
+ if self._setup_complete:
+ return
+
+ setup_future = self._setup_future
+ should_initialize = setup_future is None
+ if should_initialize:
+ setup_future = Future[None]()
+ self._setup_future = setup_future
+
+ if not should_initialize:
+ await shield(wrap_future(setup_future))
+ return
- self._setup_complete = True
-
- await self._seed_store()
+ backend_setup_complete = False
+ try:
+ await self._setup()
+ backend_setup_complete = True
+ await self._seed_store()
+ except Exception as e:
+ setup_error = StoreSetupError(message=f"Failed to setup key value
store: {e}", extra_info={"store": self.__class__.__name__})
+ cleanup_error: BaseException | None = None
+ try:
+ await self._cleanup_failed_setup()
+ except BaseException as error:
+ cleanup_error = error
+ with self._setup_state_lock:
+ # A backend setup failure can be retried. Once setup succeeded,
+ # cleanup may close backend-specific state, so a seeding
failure
+ # remains terminal for this store instance.
+ if not backend_setup_complete:
+ self._setup_future = None
+ setup_future.set_exception(setup_error)
+ if cleanup_error is not None:
+ raise setup_error from cleanup_error
+ raise setup_error from e
+ except BaseException as setup_error:
+ cleanup_error = None
+ try:
+ await self._cleanup_failed_setup()
+ except BaseException as error:
+ cleanup_error = error
+ with self._setup_state_lock:
+ if not backend_setup_complete:
+ self._setup_future = None
+ setup_future.set_exception(
+ StoreSetupError(message="Store setup was interrupted",
extra_info={"store": self.__class__.__name__})
+ )
+ if cleanup_error is not None:
+ raise setup_error from cleanup_error
+ raise
+ else:
+ with self._setup_state_lock:
+ self._setup_complete = True
+ self._setup_future = None
+ setup_future.set_result(None)
async def setup_collection(self, *, collection: str) -> None:
"""Initialize a specific collection if not already initialized.
- This method is called automatically before any collection-specific
operations and uses a per-collection
- lock to ensure thread-safe lazy initialization. It can also be called
manually to ensure a collection
- is ready before performing operations on it. The setup process
includes calling the `_setup_collection()`
- hook for store-specific collection initialization.
+ This method is called automatically before any collection-specific
operations and
+ coordinates lazy initialization across threads and event loops. The
setup process includes
+ calling the `_setup_collection()` hook for store-specific collection
initialization.
This method is idempotent - calling it multiple times for the same
collection has no additional effect
after the first call.
@@ -188,14 +248,38 @@
"""
await self.setup()
- if not self._setup_collection_complete[collection]:
- async with self._setup_collection_locks[collection]:
- if not self._setup_collection_complete[collection]:
- try:
- await self._setup_collection(collection=collection)
- except Exception as e:
- raise StoreSetupError(message=f"Failed to setup
collection: {e}", extra_info={"collection": collection}) from e
- self._setup_collection_complete[collection] = True
+ with self._setup_state_lock:
+ if self._setup_collection_complete[collection]:
+ return
+
+ setup_future = self._setup_collection_futures.get(collection)
+ should_initialize = setup_future is None
+ if should_initialize:
+ setup_future = Future[None]()
+ self._setup_collection_futures[collection] = setup_future
+
+ if not should_initialize:
+ await shield(wrap_future(setup_future))
+ return
+
+ try:
+ await self._setup_collection(collection=collection)
+ except Exception as e:
+ setup_error = StoreSetupError(message=f"Failed to setup
collection: {e}", extra_info={"collection": collection})
+ with self._setup_state_lock:
+ del self._setup_collection_futures[collection]
+ setup_future.set_exception(setup_error)
+ raise setup_error from e
+ except BaseException:
+ with self._setup_state_lock:
+ del self._setup_collection_futures[collection]
+ setup_future.set_exception(StoreSetupError(message="Collection
setup was interrupted", extra_info={"collection": collection}))
+ raise
+ else:
+ with self._setup_state_lock:
+ self._setup_collection_complete[collection] = True
+ del self._setup_collection_futures[collection]
+ setup_future.set_result(None)
@abstractmethod
async def _get_managed_entry(self, *, collection: str, key: str) ->
ManagedEntry | None:
@@ -493,14 +577,11 @@
method is called, allowing stores to register cleanup callbacks during
setup.
"""
await self._ensure_exit_stack_entered()
- try:
- await super().setup()
- except Exception as setup_error:
- try:
- await self.close()
- except Exception as close_error:
- raise setup_error from close_error
- raise
+ await super().setup()
+
+ @override
+ async def _cleanup_failed_setup(self) -> None:
+ await self.close()
class BaseEnumerateCollectionsStore(BaseStore,
AsyncEnumerateCollectionsProtocol, ABC):
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/py_key_value_aio-0.4.6/src/key_value/aio/stores/disk/multi_store.py
new/py_key_value_aio-0.5.0/src/key_value/aio/stores/disk/multi_store.py
--- old/py_key_value_aio-0.4.6/src/key_value/aio/stores/disk/multi_store.py
1970-01-01 01:00:00.000000000 +0100
+++ new/py_key_value_aio-0.5.0/src/key_value/aio/stores/disk/multi_store.py
1970-01-01 01:00:00.000000000 +0100
@@ -35,7 +35,12 @@
class MultiDiskStore(BaseContextManagerStore, BaseStore):
"""A disk-based store that uses the diskcache library to store data. The
MultiDiskStore by default creates
one diskcache Cache instance per collection created by the caller but a
custom factory function can be provided
- to tightly control the creation of the diskcache Cache instances."""
+ to tightly control the creation of the diskcache Cache instances.
+
+ The default factory validates resolved collection paths during setup.
Callers must keep
+ the base directory layout stable while caches are in use; concurrent
external filesystem
+ changes are not coordinated by this store.
+ """
_cache: dict[str, Cache]
@@ -63,7 +68,8 @@
"""Initialize a multi-disk store that creates one diskcache Cache
instance per collection created by the caller.
Args:
- base_directory: The directory to use for the disk caches.
+ base_directory: The directory to use for the disk caches. The
default factory requires
+ each collection's resolved directory to be a proper descendant
of this directory.
max_size: The maximum size of the disk caches.
default_collection: The default collection to use if no collection
is provided.
auto_create: Whether to automatically create directories if they
don't exist. Defaults to True.
@@ -82,7 +88,8 @@
Args:
disk_cache_factory: A factory function that creates a diskcache
Cache instance for a given collection.
- base_directory: The directory to use for the disk caches.
+ base_directory: The directory to use for the disk caches. The
default factory requires
+ each collection's resolved directory to be a proper descendant
of this directory.
max_size: The maximum size of the disk caches.
default_collection: The default collection to use if no collection
is provided.
auto_create: Whether to automatically create directories if they
don't exist. Defaults to True.
@@ -102,7 +109,11 @@
"""Create a default disk cache factory that creates a diskcache
Cache instance for a given collection."""
sanitized_collection: str =
_sanitize_collection_for_filesystem(collection=collection)
- cache_directory: Path = self._base_directory / sanitized_collection
+ cache_directory: Path = (self._base_directory /
sanitized_collection).resolve()
+
+ if cache_directory == self._base_directory or not
cache_directory.is_relative_to(self._base_directory):
+ msg = f"Collection '{collection}' must resolve to a directory
within '{self._base_directory}'."
+ raise ValueError(msg)
if not cache_directory.exists():
if not self._auto_create:
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/py_key_value_aio-0.4.6/src/key_value/aio/stores/disk/store.py
new/py_key_value_aio-0.5.0/src/key_value/aio/stores/disk/store.py
--- old/py_key_value_aio-0.4.6/src/key_value/aio/stores/disk/store.py
1970-01-01 01:00:00.000000000 +0100
+++ new/py_key_value_aio-0.5.0/src/key_value/aio/stores/disk/store.py
1970-01-01 01:00:00.000000000 +0100
@@ -167,7 +167,7 @@
self._client_provided_by_user = client_provided
self._auto_create = auto_create
- if disk_cache:
+ if disk_cache is not None:
self._cache = disk_cache
elif directory:
directory = Path(directory)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/py_key_value_aio-0.4.6/src/key_value/aio/stores/dynamodb/store.py
new/py_key_value_aio-0.5.0/src/key_value/aio/stores/dynamodb/store.py
--- old/py_key_value_aio-0.4.6/src/key_value/aio/stores/dynamodb/store.py
1970-01-01 01:00:00.000000000 +0100
+++ new/py_key_value_aio-0.5.0/src/key_value/aio/stores/dynamodb/store.py
1970-01-01 01:00:00.000000000 +0100
@@ -10,17 +10,20 @@
)
try:
- import aioboto3
- from aioboto3.session import Session
+ from aiobotocore.session import get_session
except ImportError as e:
msg = "DynamoDBStore requires py-key-value-aio[dynamodb]"
raise ImportError(msg) from e
-# aioboto3 generates types at runtime, so we use AioBaseClient at runtime but
DynamoDBClient during static type checking
+# aiobotocore generates client methods at runtime, so we use AioBaseClient at
runtime but DynamoDBClient during static type checking
if TYPE_CHECKING:
+ from aiobotocore.session import ClientCreatorContext
from types_aiobotocore_dynamodb.client import DynamoDBClient
+
+ DynamoDBClientContext = ClientCreatorContext[DynamoDBClient]
else:
from aiobotocore.client import AioBaseClient as DynamoDBClient
+ from aiobotocore.session import ClientCreatorContext as
DynamoDBClientContext
DEFAULT_PAGE_SIZE = 1000
PAGE_LIMIT = 1000
@@ -30,27 +33,25 @@
# These are module-level functions (not methods) so they are not exported with
the store class
-def _create_dynamodb_session(
+def _create_dynamodb_client_context(
*,
region_name: str | None = None,
+ endpoint_url: str | None = None,
aws_access_key_id: str | None = None,
aws_secret_access_key: str | None = None,
aws_session_token: str | None = None,
-) -> Session:
- """Create an aioboto3 session for DynamoDB."""
- return aioboto3.Session(
+) -> DynamoDBClientContext:
+ """Create a DynamoDB client context manager; the client exists only once
the context is entered."""
+ return get_session().create_client(
+ "dynamodb",
region_name=region_name,
+ endpoint_url=endpoint_url,
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
aws_session_token=aws_session_token,
)
-def _create_dynamodb_client_context(session: Session, *, endpoint_url: str |
None = None) -> Any:
- """Create a DynamoDB client context manager from a session."""
- return session.client(service_name="dynamodb", endpoint_url=endpoint_url)
# pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]
-
-
async def _describe_dynamodb_table(client: DynamoDBClient, table_name: str) ->
bool:
"""Check if a DynamoDB table exists.
@@ -155,9 +156,9 @@
- key (sort key)
"""
- _session: aioboto3.Session | None
+ # Settings for the client the store creates itself; each setup attempt
needs a fresh client context.
+ _client_settings: dict[str, str | None]
_table_name: str
- _endpoint_url: str | None
_client: DynamoDBClient | None
_table_config: dict[str, Any]
_auto_create: bool
@@ -251,16 +252,15 @@
if client is not None:
self._client = client
- self._session = None
- self._endpoint_url = None
+ self._client_settings = {}
else:
- self._session = _create_dynamodb_session(
- region_name=region_name,
- aws_access_key_id=aws_access_key_id,
- aws_secret_access_key=aws_secret_access_key,
- aws_session_token=aws_session_token,
- )
- self._endpoint_url = endpoint_url
+ self._client_settings = {
+ "region_name": region_name,
+ "endpoint_url": endpoint_url,
+ "aws_access_key_id": aws_access_key_id,
+ "aws_secret_access_key": aws_secret_access_key,
+ "aws_session_token": aws_session_token,
+ }
self._client = None
super().__init__(
@@ -279,12 +279,8 @@
async def _setup(self) -> None:
"""Setup the DynamoDB client and ensure table exists."""
# Register client cleanup if we own the client
- if not self._client_provided_by_user and self._client is None:
- if self._session is None:
- msg = "DynamoDB session not initialized"
- raise ValueError(msg)
- raw_client = _create_dynamodb_client_context(self._session,
endpoint_url=self._endpoint_url)
- self._client = await
self._exit_stack.enter_async_context(raw_client)
+ if not self._client_provided_by_user:
+ self._client = await
self._exit_stack.enter_async_context(_create_dynamodb_client_context(**self._client_settings))
try:
table_exists = await
_describe_dynamodb_table(self._connected_client, self._table_name)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/py_key_value_aio-0.4.6/src/key_value/aio/stores/memcached/store.py
new/py_key_value_aio-0.5.0/src/key_value/aio/stores/memcached/store.py
--- old/py_key_value_aio-0.4.6/src/key_value/aio/stores/memcached/store.py
1970-01-01 01:00:00.000000000 +0100
+++ new/py_key_value_aio-0.5.0/src/key_value/aio/stores/memcached/store.py
1970-01-01 01:00:00.000000000 +0100
@@ -1,3 +1,5 @@
+import math
+import time
from collections.abc import Sequence
from typing import Any, overload
@@ -15,6 +17,29 @@
raise ImportError(msg) from e
+# Memcached treats an exptime above 30 days as an absolute Unix timestamp, not
a duration.
+MAX_RELATIVE_EXPTIME = 60 * 60 * 24 * 30
+# Memcached parses exptime as a signed 32-bit integer, so absolute timestamps
stop in January 2038.
+MAX_ABSOLUTE_EXPTIME = 2**31 - 1
+
+
+def _exptime_from_ttl(*, ttl: float | None, now: float) -> int:
+ """Convert a remaining TTL in seconds to a Memcached exptime.
+
+ Returns 0 (no expiration) when there is no TTL. A TTL up to 30 days is
sent as a
+ relative duration of at least 1 second, since 0 means no expiration. A
longer TTL is
+ sent as an absolute Unix timestamp, because Memcached reads any larger
value that
+ way; that expiry is compared against the Memcached server's clock. Absolute
+ timestamps are capped at the largest value Memcached accepts (2038-01-19);
the
+ stored entry keeps its real expiry, which reads still check.
+ """
+ if ttl is None:
+ return 0
+ if ttl <= MAX_RELATIVE_EXPTIME:
+ return max(int(ttl), 1)
+ return min(math.ceil(now + ttl), MAX_ABSOLUTE_EXPTIME)
+
+
# Module-level helper functions for Memcached client operations
@@ -178,13 +203,7 @@
) -> None:
combo_key: str =
self._sanitize_key(compound_key(collection=collection, key=key))
- # Memcached treats 0 as no-expiration. Do not pass <= 0 (other than 0)
to avoid permanence errors.
- exptime: int
-
- if managed_entry.ttl is None: # noqa: SIM108
- exptime = 0
- else:
- exptime = max(int(managed_entry.ttl), 1)
+ exptime: int = _exptime_from_ttl(ttl=managed_entry.ttl,
now=time.time())
json_value: str =
self._serialization_adapter.dump_json(entry=managed_entry, key=key,
collection=collection)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/py_key_value_aio-0.4.6/src/key_value/aio/stores/redis/store.py
new/py_key_value_aio-0.5.0/src/key_value/aio/stores/redis/store.py
--- old/py_key_value_aio-0.4.6/src/key_value/aio/stores/redis/store.py
1970-01-01 01:00:00.000000000 +0100
+++ new/py_key_value_aio-0.5.0/src/key_value/aio/stores/redis/store.py
1970-01-01 01:00:00.000000000 +0100
@@ -148,19 +148,23 @@
return await client.get(name=name)
+async def _close_redis_client(client: Redis) -> None:
+ """Close clients from both redis-py 4.x and newer releases."""
+ aclose = getattr(client, "aclose", None)
+ if aclose is not None:
+ await aclose()
+ else:
+ await client.close()
+
+
async def _redis_mget(client: Redis, keys: list[str]) -> list[Any]:
"""Get multiple values from Redis."""
return await client.mget(keys=keys)
-async def _redis_set(client: Redis, name: str, value: str) -> None:
- """Set a value in Redis without TTL."""
- _ = await client.set(name=name, value=value)
-
-
-async def _redis_setex(client: Redis, name: str, time: int, value: str) ->
None:
- """Set a value in Redis with TTL."""
- _ = await client.setex(name=name, time=time, value=value)
+async def _redis_set(client: Redis, name: str, value: str, *, expires_in: int
| None = None) -> None:
+ """Set a value in Redis with an optional TTL."""
+ _ = await client.set(name=name, value=value, ex=expires_in)
async def _redis_pipeline_execute(pipeline: Any) -> None:
@@ -359,7 +363,7 @@
# Redis does not support <= 0 TTLs
ttl = max(int(managed_entry.ttl), 1)
- await _redis_setex(self._client, combo_key, ttl, json_value)
+ await _redis_set(self._client, combo_key, json_value,
expires_in=ttl)
else:
await _redis_set(self._client, combo_key, json_value)
@@ -398,7 +402,7 @@
combo_key: str = compound_key(collection=collection, key=key)
json_value = self._adapter.dump_json(entry=managed_entry, key=key,
collection=collection)
- pipeline.setex(name=combo_key, time=ttl_seconds, value=json_value)
+ pipeline.set(name=combo_key, value=json_value, ex=ttl_seconds)
await _redis_pipeline_execute(pipeline)
@@ -425,16 +429,26 @@
pattern = compound_key(collection=collection, key="*")
- # redis.asyncio scan returns tuple(cursor, keys)
- _cursor, keys = await _redis_scan(self._client, cursor=0,
match=pattern, count=limit)
-
- return get_keys_from_compound_keys(compound_keys=keys,
collection=collection)
+ cursor = 0
+ keys: list[str] = []
+ seen: set[str] = set()
+ while True:
+ # SCAN may return an empty page with a nonzero cursor, or repeat
keys.
+ cursor, page = await _redis_scan(self._client, cursor=cursor,
match=pattern, count=limit)
+ for key in get_keys_from_compound_keys(compound_keys=page,
collection=collection):
+ if key not in seen:
+ seen.add(key)
+ keys.append(key)
+ if len(keys) >= limit:
+ return keys
+ if cursor == 0:
+ return keys
@override
async def _setup(self) -> None:
"""Register client cleanup if we own the client."""
if not self._client_provided_by_user:
- self._exit_stack.push_async_callback(self._client.aclose)
+ self._exit_stack.push_async_callback(_close_redis_client,
self._client)
@override
async def _delete_store(self) -> bool:
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/py_key_value_aio-0.4.6/src/key_value/aio/stores/s3/store.py
new/py_key_value_aio-0.5.0/src/key_value/aio/stores/s3/store.py
--- old/py_key_value_aio-0.4.6/src/key_value/aio/stores/s3/store.py
1970-01-01 01:00:00.000000000 +0100
+++ new/py_key_value_aio-0.5.0/src/key_value/aio/stores/s3/store.py
1970-01-01 01:00:00.000000000 +0100
@@ -18,44 +18,45 @@
MAX_KEY_LENGTH = 500
try:
- import aioboto3
- from aioboto3.session import Session
+ from aiobotocore.session import get_session
except ImportError as e:
msg = "S3Store requires py-key-value-aio[s3]"
raise ImportError(msg) from e
-# aioboto3 generates types at runtime, so we use AioBaseClient at runtime but
S3Client during static type checking
+# aiobotocore generates client methods at runtime, so we use AioBaseClient at
runtime but S3Client during static type checking
if TYPE_CHECKING:
+ from aiobotocore.session import ClientCreatorContext
from types_aiobotocore_s3.client import S3Client
+
+ S3ClientContext = ClientCreatorContext[S3Client]
else:
from aiobotocore.client import AioBaseClient as S3Client
+ from aiobotocore.session import ClientCreatorContext as S3ClientContext
# Private helper functions to encapsulate S3/boto3 client interactions with
type ignore comments
# These are module-level functions (not methods) so they are not exported with
the store class
-def _create_s3_session(
+def _create_s3_client_context(
*,
region_name: str | None = None,
+ endpoint_url: str | None = None,
aws_access_key_id: str | None = None,
aws_secret_access_key: str | None = None,
aws_session_token: str | None = None,
-) -> Session:
- """Create an aioboto3 session for S3."""
- return aioboto3.Session(
+) -> S3ClientContext:
+ """Create an S3 client context manager; the client exists only once the
context is entered."""
+ return get_session().create_client(
+ "s3",
region_name=region_name,
+ endpoint_url=endpoint_url,
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
aws_session_token=aws_session_token,
)
-def _create_s3_client_context(session: Session, *, endpoint_url: str | None =
None) -> Any:
- """Create an S3 client context manager from a session."""
- return session.client(service_name="s3", endpoint_url=endpoint_url) #
pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]
-
-
async def _head_s3_bucket(client: S3Client, bucket_name: str) -> None:
"""Check if an S3 bucket exists."""
await client.head_bucket(Bucket=bucket_name)
@@ -140,10 +141,10 @@
Key=key,
)
except ClientError as e:
- error = e.response.get("Error", {}) # pyright:
ignore[reportUnknownMemberType, reportUnknownVariableType]
- metadata = e.response.get("ResponseMetadata", {}) # pyright:
ignore[reportUnknownMemberType, reportUnknownVariableType]
- error_code = error.get("Code", "") # pyright:
ignore[reportUnknownMemberType, reportUnknownVariableType]
- http_status = metadata.get("HTTPStatusCode", 0) # pyright:
ignore[reportUnknownMemberType, reportUnknownVariableType]
+ error = e.response.get("Error", {})
+ metadata = e.response.get("ResponseMetadata", {})
+ error_code = error.get("Code", "")
+ http_status = metadata.get("HTTPStatusCode", 0)
if error_code in ("404", "NoSuchKey") or http_status == HTTP_NOT_FOUND:
return False
@@ -164,7 +165,7 @@
if not isinstance(e, ClientError):
return ""
- return e.response.get("Error", {}).get("Code", "") # pyright:
ignore[reportUnknownMemberType, reportUnknownVariableType]
+ return e.response.get("Error", {}).get("Code", "")
def _get_botocore_http_status(e: Exception) -> int:
@@ -173,7 +174,7 @@
if not isinstance(e, ClientError):
return 0
- return e.response.get("ResponseMetadata", {}).get("HTTPStatusCode", 0) #
pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]
+ return e.response.get("ResponseMetadata", {}).get("HTTPStatusCode", 0)
class S3KeySanitizationStrategy(SanitizationStrategy):
@@ -277,7 +278,8 @@
_bucket_name: str
_endpoint_url: str | None
- _raw_client: Any
+ # Settings for the client the store creates itself; each setup attempt
needs a fresh client context.
+ _client_settings: dict[str, str | None]
_client: S3Client | None
@overload
@@ -365,16 +367,15 @@
if client:
self._client = client
- self._raw_client = None
+ self._client_settings = {}
else:
- session = _create_s3_session(
- region_name=region_name,
- aws_access_key_id=aws_access_key_id,
- aws_secret_access_key=aws_secret_access_key,
- aws_session_token=aws_session_token,
- )
-
- self._raw_client = _create_s3_client_context(session,
endpoint_url=endpoint_url)
+ self._client_settings = {
+ "region_name": region_name,
+ "endpoint_url": endpoint_url,
+ "aws_access_key_id": aws_access_key_id,
+ "aws_secret_access_key": aws_secret_access_key,
+ "aws_session_token": aws_session_token,
+ }
self._client = None
super().__init__(
@@ -407,8 +408,8 @@
HeadBucket operation to check for bucket existence and creates it if
not found.
"""
# Register client cleanup if we own the client
- if not self._client_provided_by_user and self._raw_client is not None:
- self._client = await
self._exit_stack.enter_async_context(self._raw_client)
+ if not self._client_provided_by_user:
+ self._client = await
self._exit_stack.enter_async_context(_create_s3_client_context(**self._client_settings))
from botocore.exceptions import ClientError
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/py_key_value_aio-0.4.6/src/key_value/aio/stores/simple/store.py
new/py_key_value_aio-0.5.0/src/key_value/aio/stores/simple/store.py
--- old/py_key_value_aio-0.4.6/src/key_value/aio/stores/simple/store.py
1970-01-01 01:00:00.000000000 +0100
+++ new/py_key_value_aio-0.5.0/src/key_value/aio/stores/simple/store.py
1970-01-01 01:00:00.000000000 +0100
@@ -65,7 +65,7 @@
async def _put_managed_entry(self, *, key: str, collection: str,
managed_entry: ManagedEntry) -> None:
combo_key: str = compound_key(collection=collection, key=key)
- if len(self._data) >= self.max_entries:
+ if combo_key not in self._data and len(self._data) >= self.max_entries:
_ = self._data.pop(next(iter(self._data)))
self._data[combo_key] = SimpleStoreEntry(
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/py_key_value_aio-0.4.6/src/key_value/aio/stores/valkey/store.py
new/py_key_value_aio-0.5.0/src/key_value/aio/stores/valkey/store.py
--- old/py_key_value_aio-0.4.6/src/key_value/aio/stores/valkey/store.py
1970-01-01 01:00:00.000000000 +0100
+++ new/py_key_value_aio-0.5.0/src/key_value/aio/stores/valkey/store.py
1970-01-01 01:00:00.000000000 +0100
@@ -1,3 +1,4 @@
+import math
from collections.abc import Sequence
from typing import overload
@@ -29,6 +30,18 @@
PAGE_LIMIT = 10000
+def _expiry_from_ttl(*, ttl: float | None) -> ExpirySet | None:
+ """Convert a remaining TTL in seconds to a Valkey expiry.
+
+ Uses millisecond precision so that sub-second TTLs are accepted (Valkey
rejects an
+ expiry of 0 seconds). The value is rounded up and is at least 1
millisecond, so an
+ entry is never written without an expiry or with an invalid one.
+ """
+ if ttl is None:
+ return None
+ return ExpirySet(expiry_type=ExpiryType.MILLSEC, value=max(math.ceil(ttl *
1000), 1))
+
+
# Private helper functions to encapsulate Valkey/Glide client creation with
type ignore comments
# These are module-level functions (not methods) so they are not exported with
the store class
@@ -229,7 +242,7 @@
json_value: str =
self._serialization_adapter.dump_json(entry=managed_entry, key=key,
collection=collection)
- expiry: ExpirySet | None = ExpirySet(expiry_type=ExpiryType.SEC,
value=int(managed_entry.ttl)) if managed_entry.ttl else None
+ expiry: ExpirySet | None = _expiry_from_ttl(ttl=managed_entry.ttl)
_ = await self._client.set(key=combo_key, value=json_value,
expiry=expiry)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/py_key_value_aio-0.4.6/src/key_value/aio/wrappers/passthrough_cache/wrapper.py
new/py_key_value_aio-0.5.0/src/key_value/aio/wrappers/passthrough_cache/wrapper.py
---
old/py_key_value_aio-0.4.6/src/key_value/aio/wrappers/passthrough_cache/wrapper.py
1970-01-01 01:00:00.000000000 +0100
+++
new/py_key_value_aio-0.5.0/src/key_value/aio/wrappers/passthrough_cache/wrapper.py
1970-01-01 01:00:00.000000000 +0100
@@ -46,12 +46,13 @@
@override
async def get(self, key: str, *, collection: str | None = None) ->
dict[str, Any] | None:
- if managed_entry := await
self.cache_key_value.get(collection=collection, key=key):
- return managed_entry
+ cached_entry = await self.cache_key_value.get(collection=collection,
key=key)
+ if cached_entry is not None:
+ return cached_entry
uncached_entry, ttl = await
self.primary_key_value.ttl(collection=collection, key=key)
- if not uncached_entry:
+ if uncached_entry is None:
return None
await self.cache_key_value.put(collection=collection, key=key,
value=uncached_entry, ttl=ttl)
@@ -88,12 +89,12 @@
async def ttl(self, key: str, *, collection: str | None = None) ->
tuple[dict[str, Any] | None, float | None]:
cached_entry, ttl = await
self.cache_key_value.ttl(collection=collection, key=key)
- if cached_entry:
+ if cached_entry is not None:
return cached_entry, ttl
uncached_entry, ttl = await
self.primary_key_value.ttl(collection=collection, key=key)
- if not uncached_entry:
+ if uncached_entry is None:
return (None, None)
await self.cache_key_value.put(collection=collection, key=key,
value=uncached_entry, ttl=ttl)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/py_key_value_aio-0.4.6/src/key_value/aio/wrappers/statistics/wrapper.py
new/py_key_value_aio-0.5.0/src/key_value/aio/wrappers/statistics/wrapper.py
--- old/py_key_value_aio-0.4.6/src/key_value/aio/wrappers/statistics/wrapper.py
1970-01-01 01:00:00.000000000 +0100
+++ new/py_key_value_aio-0.5.0/src/key_value/aio/wrappers/statistics/wrapper.py
1970-01-01 01:00:00.000000000 +0100
@@ -99,6 +99,8 @@
"""Statistics wrapper around a KV Store that tracks operation statistics.
Note: enumeration and destroy operations are not tracked by this wrapper.
+ Collection arguments pass through unchanged. Omitted or empty collection
arguments
+ use the default collection label for statistics, regardless of the
underlying store's default.
"""
def __init__(self, key_value: AsyncKeyValue) -> None:
@@ -111,62 +113,62 @@
@override
async def get(self, key: str, *, collection: str | None = None) ->
dict[str, Any] | None:
- collection = collection or DEFAULT_COLLECTION_NAME
+ statistics_collection = collection or DEFAULT_COLLECTION_NAME
value = await self.key_value.get(collection=collection, key=key)
if value is not None:
-
self.statistics.get_collection(collection=collection).get.increment_hit()
+
self.statistics.get_collection(collection=statistics_collection).get.increment_hit()
return value
-
self.statistics.get_collection(collection=collection).get.increment_miss()
+
self.statistics.get_collection(collection=statistics_collection).get.increment_miss()
return None
@override
async def ttl(self, key: str, *, collection: str | None = None) ->
tuple[dict[str, Any] | None, float | None]:
- collection = collection or DEFAULT_COLLECTION_NAME
+ statistics_collection = collection or DEFAULT_COLLECTION_NAME
value, ttl = await self.key_value.ttl(collection=collection, key=key)
if value is not None:
-
self.statistics.get_collection(collection=collection).ttl.increment_hit()
+
self.statistics.get_collection(collection=statistics_collection).ttl.increment_hit()
return value, ttl
-
self.statistics.get_collection(collection=collection).ttl.increment_miss()
+
self.statistics.get_collection(collection=statistics_collection).ttl.increment_miss()
return None, None
@override
async def put(self, key: str, value: Mapping[str, Any], *, collection: str
| None = None, ttl: SupportsFloat | None = None) -> None:
- collection = collection or DEFAULT_COLLECTION_NAME
+ statistics_collection = collection or DEFAULT_COLLECTION_NAME
await self.key_value.put(collection=collection, key=key, value=value,
ttl=ttl)
- self.statistics.get_collection(collection=collection).put.increment()
+
self.statistics.get_collection(collection=statistics_collection).put.increment()
@override
async def delete(self, key: str, *, collection: str | None = None) -> bool:
- collection = collection or DEFAULT_COLLECTION_NAME
+ statistics_collection = collection or DEFAULT_COLLECTION_NAME
if await self.key_value.delete(collection=collection, key=key):
-
self.statistics.get_collection(collection=collection).delete.increment_hit()
+
self.statistics.get_collection(collection=statistics_collection).delete.increment_hit()
return True
-
self.statistics.get_collection(collection=collection).delete.increment_miss()
+
self.statistics.get_collection(collection=statistics_collection).delete.increment_miss()
return False
@override
async def get_many(self, keys: Sequence[str], *, collection: str | None =
None) -> list[dict[str, Any] | None]:
- collection = collection or DEFAULT_COLLECTION_NAME
+ statistics_collection = collection or DEFAULT_COLLECTION_NAME
results: list[dict[str, Any] | None] = await
self.key_value.get_many(keys=keys, collection=collection)
hits = len([result for result in results if result is not None])
misses = len([result for result in results if result is None])
-
self.statistics.get_collection(collection=collection).get.increment_hit(increment=hits)
-
self.statistics.get_collection(collection=collection).get.increment_miss(increment=misses)
+
self.statistics.get_collection(collection=statistics_collection).get.increment_hit(increment=hits)
+
self.statistics.get_collection(collection=statistics_collection).get.increment_miss(increment=misses)
return results
@@ -179,36 +181,36 @@
collection: str | None = None,
ttl: SupportsFloat | None = None,
) -> None:
- collection = collection or DEFAULT_COLLECTION_NAME
+ statistics_collection = collection or DEFAULT_COLLECTION_NAME
await self.key_value.put_many(keys=keys, values=values,
collection=collection, ttl=ttl)
-
self.statistics.get_collection(collection=collection).put.increment(increment=len(keys))
+
self.statistics.get_collection(collection=statistics_collection).put.increment(increment=len(keys))
@override
async def delete_many(self, keys: Sequence[str], *, collection: str | None
= None) -> int:
- collection = collection or DEFAULT_COLLECTION_NAME
+ statistics_collection = collection or DEFAULT_COLLECTION_NAME
deleted_count: int = await self.key_value.delete_many(keys=keys,
collection=collection)
hits = deleted_count
misses = len(keys) - deleted_count
-
self.statistics.get_collection(collection=collection).delete.increment_hit(increment=hits)
-
self.statistics.get_collection(collection=collection).delete.increment_miss(increment=misses)
+
self.statistics.get_collection(collection=statistics_collection).delete.increment_hit(increment=hits)
+
self.statistics.get_collection(collection=statistics_collection).delete.increment_miss(increment=misses)
return deleted_count
@override
async def ttl_many(self, keys: Sequence[str], *, collection: str | None =
None) -> list[tuple[dict[str, Any] | None, float | None]]:
- collection = collection or DEFAULT_COLLECTION_NAME
+ statistics_collection = collection or DEFAULT_COLLECTION_NAME
results: list[tuple[dict[str, Any] | None, float | None]] = await
self.key_value.ttl_many(keys=keys, collection=collection)
hits = len([result for result in results if result[0] is not None])
misses = len([result for result in results if result[0] is None])
-
self.statistics.get_collection(collection=collection).ttl.increment_hit(increment=hits)
-
self.statistics.get_collection(collection=collection).ttl.increment_miss(increment=misses)
+
self.statistics.get_collection(collection=statistics_collection).ttl.increment_hit(increment=hits)
+
self.statistics.get_collection(collection=statistics_collection).ttl.increment_miss(increment=misses)
return results
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/py_key_value_aio-0.4.6/src/key_value/aio/wrappers/ttl_clamp/wrapper.py
new/py_key_value_aio-0.5.0/src/key_value/aio/wrappers/ttl_clamp/wrapper.py
--- old/py_key_value_aio-0.4.6/src/key_value/aio/wrappers/ttl_clamp/wrapper.py
1970-01-01 01:00:00.000000000 +0100
+++ new/py_key_value_aio-0.5.0/src/key_value/aio/wrappers/ttl_clamp/wrapper.py
1970-01-01 01:00:00.000000000 +0100
@@ -25,7 +25,8 @@
key_value: The store to wrap.
min_ttl: The minimum TTL for puts into the store.
max_ttl: The maximum TTL for puts into the store.
- missing_ttl: The TTL to use for entries that do not have a TTL.
Defaults to None.
+ missing_ttl: The TTL to use for entries that do not have a TTL,
clamped to the same bounds.
+ Defaults to None, preserving entries without expiration.
"""
self.key_value: AsyncKeyValue = key_value
self.min_ttl: float = float(min_ttl)
@@ -42,7 +43,9 @@
def _ttl_clamp(self, ttl: SupportsFloat | None) -> float | None:
if ttl is None:
- return self.missing_ttl
+ ttl = self.missing_ttl
+ if ttl is None:
+ return None
ttl = prepare_ttl(t=ttl)