From 17dbb9d4bceddc4679d102e1f029a03926d819b9 Mon Sep 17 00:00:00 2001 From: allen0099 Date: Sat, 26 Sep 2026 13:30:50 +0000 Subject: [PATCH] feat: export CacheXError, BackendNotFoundError and RequestNotFoundError @cache and the proxies raise these exceptions, but unlike every session and state exception they were only importable from fastapi_cachex.exceptions. Re-export them from the package next to LockTimeoutError. Closes #160 --- fastapi_cachex/__init__.py | 6 ++++++ tests/test_exports.py | 14 ++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/test_exports.py diff --git a/fastapi_cachex/__init__.py b/fastapi_cachex/__init__.py index 78f8b20..ec89120 100644 --- a/fastapi_cachex/__init__.py +++ b/fastapi_cachex/__init__.py @@ -11,7 +11,10 @@ from .dependencies import CacheBackend as CacheBackend from .dependencies import get_app_cache as get_app_cache from .dependencies import get_cache_backend as get_cache_backend +from .exceptions import BackendNotFoundError as BackendNotFoundError +from .exceptions import CacheXError as CacheXError from .exceptions import LockTimeoutError as LockTimeoutError +from .exceptions import RequestNotFoundError as RequestNotFoundError from .lock import CacheLock as CacheLock from .manager import CacheManager as CacheManager from .manager_proxy import CacheManagerProxy as CacheManagerProxy @@ -68,15 +71,18 @@ def _read_version() -> str: __all__ = [ "AppCache", + "BackendNotFoundError", "BackendProxy", "CacheBackend", "CacheKeyBuilder", "CacheLock", "CacheManager", "CacheManagerProxy", + "CacheXError", "FastAPICacheXSessionMiddleware", "InvalidStateError", "LockTimeoutError", + "RequestNotFoundError", "Session", "SessionConfig", "SessionError", diff --git a/tests/test_exports.py b/tests/test_exports.py new file mode 100644 index 0000000..f763b67 --- /dev/null +++ b/tests/test_exports.py @@ -0,0 +1,14 @@ +"""Exceptions raised by the core are importable from the package (#160).""" + +import pytest + +import fastapi_cachex +from fastapi_cachex import exceptions + + +@pytest.mark.parametrize( + "name", ["BackendNotFoundError", "CacheXError", "RequestNotFoundError"] +) +def test_core_exception_is_exported(name: str) -> None: + assert name in fastapi_cachex.__all__ + assert getattr(fastapi_cachex, name) is getattr(exceptions, name)