feat: warn about every 0.4.0 breaking change in 0.3.9 - #358
Merged
Merged
Conversation
0.3.9 is the last 0.3.x release, so it announces every 0.4.0 change it can: - FastAPICacheXSessionMiddleware emits a FutureWarning while its config relies on the cookie_name / cookie_https_only defaults, which become __Host-session with Secure (#256); SessionConfig emits a UserWarning for __Host-/__Secure- settings browsers refuse. - CacheManager.get_or_set() emits a FutureWarning, once per manager, while neither the call nor the manager chose lock= (#280); lock=None now means "not chosen". - get_session_manager emits a FutureWarning, once per app, when SessionManagerProxy does not hold the middleware's manager (#131). - Passing the Redis encoding option emits a DeprecationWarning (#126), and the short JWT key warning says 0.4.0 rejects it (#129). Adds a Migrating to 0.4.0 page (English and zh-TW) covering every 0.4.0 milestone item, changelog fragments, and the release notice in CHANGELOG.md. Closes #352
allen0099
force-pushed
the
feat/352-0-4-0-deprecations
branch
from
September 29, 2026 08:17
1820876 to
80f2168
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
0.3.9 is the last 0.3.x release. This PR adds a warning for every 0.4.0 breaking change that 0.3.9 can detect, a "Migrating to 0.4.0" page covering the whole 0.4.0 milestone, and the release notice.
Closes #352
New warnings
FutureWarningFastAPICacheXSessionMiddlewareis built, if its config leavescookie_nameorcookie_https_onlyat the defaultcookie_name="session", cookie_https_only=Falsekeeps today's cookie, or"__Host-session"+Trueswitches nowUserWarningSessionConfigwith a__Host-name withoutcookie_https_only=True, withcookie_path != "/"or with acookie_domain, or a__Secure-name withoutcookie_https_only=Trueget_or_setlockFutureWarningget_or_set()call that passes nolock=when the manager was created withoutlock=lock=False/Trueper call or onCacheManager(...); forAppCache,CacheManagerProxy.set(CacheManager(lock=...))get_session_managerFutureWarningget_session_manager(andSessionManagerDep,ClientIPDep,rotate_session_id()) returns the middleware's manager butSessionManagerProxyholds none or a different oneSessionManagerProxy.set(session_manager)at startupencodingDeprecationWarningAsyncRedisCacheBackend(encoding=...)or aRedisConfigwithencodingset, passed toload_from_config()RuntimeWarningand get no second warningUserWarningThe messages follow the existing ones (#298, #125): they name what is relied on, say "Version 0.4.0 …", give the fix, and end with the issue link.
stacklevelpoints at the user's call: for the middleware, that isadd_middleware/the first request, since Starlette builds the stack lazily.Warning texts:
FastAPICacheXSessionMiddleware is using the default cookie_name and cookie_https_only of SessionConfig. Version 0.4.0 changes the session cookie defaults to cookie_name='__Host-session' with the Secure flag (cookie_https_only=True): the new name logs every cookie session out once on upgrade, and a Secure cookie is not sent over plain HTTP. Set both explicitly: cookie_name='session', cookie_https_only=False keeps the current cookie; cookie_name='__Host-session', cookie_https_only=True switches now (https://github.com/allen0099/FastAPI-CacheX/issues/256).cookie_name='__Host-session' requires cookie_https_only=True: browsers refuse a cookie with this prefix otherwise, so the session cookie would never be stored. Version 0.4.0 will reject this configuration.CacheManager.get_or_set() is relying on the default lock=False: neither the call nor CacheManager(...) passed lock=. Version 0.4.0 turns stampede protection on by default (lock=True). Pass lock=False to keep the current behaviour, or lock=True to opt in now, to get_or_set() or to CacheManager() (for AppCache, register one with CacheManagerProxy.set()) (https://github.com/allen0099/FastAPI-CacheX/issues/280).get_session_managerthroughSessionManagerProxy#131:get_session_manager() returned the SessionManager the session middleware registered, which is not the one set in SessionManagerProxy. Version 0.4.0 resolves get_session_manager() (and SessionManagerDep, ClientIPDep and rotate_session_id(), which use it) through SessionManagerProxy only. Call SessionManagerProxy.set(session_manager) at startup (https://github.com/allen0099/FastAPI-CacheX/issues/131).encodingoption and read raw bytes #126:AsyncRedisCacheBackend(encoding='utf-8') is deprecated. Version 0.4.0 removes it: the client will read raw bytes, and entries are always UTF-8. Remove the argument; UTF-8 is what you get without it (https://github.com/allen0099/FastAPI-CacheX/issues/126).(the same text withRedisConfig(encoding=...)forload_from_config)Decisions
SessionConfig. OnlyFastAPICacheXSessionMiddlewaresends the cookie. A warning inSessionConfigwould also hit header-only users (the deprecatedSessionMiddleware, bareSessionManager), who are unaffected. The warning coverscookie_https_onlytoo: theSecuredefault is what breaks plain-HTTP development. Either explicit form silences it and keeps working on 0.4.0. Not detectable at runtime, so docs only: the rest of 0.4.0: explicit login()/logout() that always rotate the session ID, and __Host- cookie by default #256 (read-onlySession.user, login starting a new session, grace period, logout API). Their shape is still undecided, and a warning now could point users at the wrong replacement;login()already exists and the migration page recommends it.get_or_set(), not at construction. This deviates from the plan in 0.4.0: enable get_or_set() stampede protection by default #280, which proposed warning atCacheManager()construction and skipping theAppCachedefault manager. A construction-time warning would fire for managers that never callget_or_set()and are unaffected. SkippingAppCachewould leave the most common path silent, even though the user wrote theget_or_set()call whose behaviour changes. The warning fires only when neither the manager nor the call chose, once per manager, and a per-calllock=silences it without registering a manager.CacheManager(lock=None)is now accepted as "not chosen" (it used to raiseTypeError);manager.lockis still abool.get_session_managerthroughSessionManagerProxy#131: warn only when the proxy disagrees. Apps that already callSessionManagerProxy.set()(the forward-compatible wiring) stay silent.encodingoption and read raw bytes #126: warn only on an explicitencoding. The parameter's default becomesNone(still meaning UTF-8), andload_from_configchecksmodel_fields_set, so only code that passes the option sees the warning. Removing that code is exactly the 0.4.0 fix.delete()returnsbool: docs only. A custom backend cannot declare-> booltoday without a mypy override error against the 0.3.x base class. The only callers of theNonereturn are the library's own. A warning would fire for everyone and could not be silenced by forward-compatible code.UserSessionDeprequire a session with a user #127UserSessionDep: docs only. A type alias has no hook that runs when it is used. A module-level__getattr__warning would fire on import for anyone who imports it, including code that is about to switch.memcacheextra: docs only. The installer resolves extras; the library cannot tell which extra was requested.CacheEntry.headers: docs only. 0.3.x cannot tell whether aclear_patternpattern or custom key builder will match the new format. The runtime cost of the key change is a single cache miss, and code that readsCacheEntry.headerscannot adopt the list shape before 0.4.0. The page coversclear_pattern("*|||*")cleanup and the rolling-deploy note for Repeated response headers are collapsed when a response is cached #105.token_source_priority: docs only. No user code changes; custom-backend requirements are not decided yet.CacheErrorexception #130, 0.4.0: remove the deprecated SessionMiddleware #69, 0.4.0: remove the Redisclear_patternprefix fallback #125, add_routes: monitoring routes are unauthenticated and expose content previews by default #298.Docs
docs/MIGRATING_0_4.mdandi18n/zh-TW/docs/MIGRATING_0_4.md: added to both navs, with{#anchor}ids and one line per paragraph. They include a summary table of every 0.4.0 milestone item (issue, warned or not, section) and a section per item with before/after code. Details still open in an issue (loginkeep=, the key format tag, sort-by-default, the Repeated response headers are collapsed when a response is cached #105 version marker, the Allow cookies in token_source_priority #75 default order, the 0.4.0: conditional session writes so a stale request cannot restore a deleted session #128 primitive) are marked as not decided.SessionManagerProxy.set()in the basic and Redis examples, a "Cookie defaults change in 0.4.0" section, and a 0.4.0 note onget_session_manager.lock=in the examples and a "The default changes in 0.4.0" subsection.__Host-session.encodingdropped from theRedisConfigexample.get_or_set(..., lock=True).app_cache.py,session_login.py,session_jwt.py) use the explicit forms, andtests/test_examples.pyruns them underfilterwarnings = error.Changelog
256.deprecated.md,256.deprecated.2.md,280.deprecated.md,131.deprecated.md,126.deprecated.md,129.deprecated.md.## [Unreleased]links tohttps://fastapi-cachex.readthedocs.io/en/stable/MIGRATING_0_4/.scripts/changelog_release.py --version 0.3.9 --dry-runprints it first.test_the_repository_changelog_can_be_releasedassumed the section opens with###; it now allows the notice above the first heading.Tests
tests/session/test_0_4_0_notices.pycovers 0.4.0: explicit login()/logout() that always rotate the session ID, and __Host- cookie by default #256 and 0.4.0: resolveget_session_managerthroughSessionManagerProxy#131. The 0.4.0: enable get_or_set() stampede protection by default #280 tests are intests/test_cache_manager.py, the 0.4.0: drop the Redisencodingoption and read raw bytes #126 tests intests/backends/test_redis.py, and the 0.4.0: reject JWT HMAC secrets shorter than the hash output #129 message check intests/session/test_token_serializers.py.Checks
pytestwith live Redis and Memcached: 1445 passed, coverage 99.82%.tox -e lowest: passed.mypy fastapi_cachex --strict: clean.pre-commit run --all-files: clean.zensical build --strict(en and zh-TW): clean.