Skip to content

feat(proxy): raise ProxyNotSetError from unset manager proxies - #220

Merged
allen0099 merged 1 commit into
masterfrom
feat/proxy-not-set-error
Sep 26, 2026
Merged

allen0099 merged 1 commit into
masterfrom
feat/proxy-not-set-error

Conversation

@allen0099

Copy link
Copy Markdown
Owner

Closes #161 (part of #113)

Problem

ProxyBase.get() raised BackendNotFoundError for every proxy. CacheManagerProxy, SessionManagerProxy and StateManagerProxy have nothing to do with a backend, so a missing session manager surfaced as "backend not found".

Change

  • New ProxyNotSetError(BackendNotFoundError) in fastapi_cachex.exceptions, exported from fastapi_cachex.
    • Subclassing keeps every existing except BackendNotFoundError working.
    • The error message is unchanged ("No instance set for proxy ...").
  • ProxyBase raises cls._not_set_error, which defaults to ProxyNotSetError. BackendProxy overrides it with BackendNotFoundError, so its behaviour does not change. A third-party ProxyBase subclass gets the new error.
  • get_app_cache and get_state_manager now catch ProxyNotSetError rather than BackendNotFoundError around the manager proxy lookup. This makes explicit that only a missing manager triggers the lazy default.
  • CHANGELOG: an Added entry. The API reference picks up the new class from the module; no other docs mention these proxies' errors.

Tests

  • tests/test_proxybackend.py:
    • each manager proxy raises ProxyNotSetError, which is also a BackendNotFoundError;
    • BackendProxy still raises plain BackendNotFoundError.
  • tests/test_exports.py lists ProxyNotSetError.

Mutation checks:

mutation tests that fail
base default back to BackendNotFoundError the three new proxy cases, plus the lazy-dependency tests (which now catch the narrower error)
drop the BackendProxy override only the BackendProxy test
ProxyNotSetError not a BackendNotFoundError subclass the new tests and the existing "raises when unset" tests

Ruff, mypy --strict, the full suite against live Redis and Memcached (902 passed), and zensical build --strict for both languages.

@allen0099 allen0099 added this to the 0.3.8 milestone Sep 26, 2026
@allen0099 allen0099 added the enhancement New feature or request label Sep 26, 2026
CacheManagerProxy, SessionManagerProxy and StateManagerProxy raised
BackendNotFoundError from get() when no instance was set, although no
backend is involved. They now raise ProxyNotSetError, a subclass of
BackendNotFoundError, so existing handlers keep working. BackendProxy
still raises BackendNotFoundError. The lazy dependencies catch the
narrower error, and ProxyNotSetError is exported from the package.

Closes #161
@allen0099
allen0099 force-pushed the feat/proxy-not-set-error branch from 54b0539 to 2246b2a Compare September 26, 2026 18:29
@allen0099
allen0099 merged commit df2cfc9 into master Sep 26, 2026
11 checks passed
@allen0099
allen0099 deleted the feat/proxy-not-set-error branch September 26, 2026 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Raise a dedicated ProxyNotSetError from manager proxies

1 participant