Skip to content

feat: warn about every 0.4.0 breaking change in 0.3.9 - #358

Merged
allen0099 merged 1 commit into
masterfrom
feat/352-0-4-0-deprecations
Sep 29, 2026
Merged

allen0099 merged 1 commit into
masterfrom
feat/352-0-4-0-deprecations

Conversation

@allen0099

Copy link
Copy Markdown
Owner

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

Issue Category When it fires How to silence it (forward compatible)
#256 cookie defaults FutureWarning Once, when FastAPICacheXSessionMiddleware is built, if its config leaves cookie_name or cookie_https_only at the default Set both: cookie_name="session", cookie_https_only=False keeps today's cookie, or "__Host-session" + True switches now
#256 contradictory prefixes UserWarning SessionConfig with a __Host- name without cookie_https_only=True, with cookie_path != "/" or with a cookie_domain, or a __Secure- name without cookie_https_only=True Fix the config (browsers already drop such a cookie). 0.4.0 rejects it
#280 get_or_set lock FutureWarning Once per manager, on a get_or_set() call that passes no lock= when the manager was created without lock= lock=False/True per call or on CacheManager(...); for AppCache, CacheManagerProxy.set(CacheManager(lock=...))
#131 get_session_manager FutureWarning Once per app, when get_session_manager (and SessionManagerDep, ClientIPDep, rotate_session_id()) returns the middleware's manager but SessionManagerProxy holds none or a different one SessionManagerProxy.set(session_manager) at startup
#126 Redis encoding DeprecationWarning AsyncRedisCacheBackend(encoding=...) or a RedisConfig with encoding set, passed to load_from_config() Leave it out (UTF-8 is what you get without it). Non-UTF-8 values keep their RuntimeWarning and get no second warning
#129 short JWT key existing UserWarning unchanged The message now ends "Version 0.4.0 will reject a shorter key (…/issues/129)."

The 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. stacklevel points at the user's call: for the middleware, that is add_middleware/the first request, since Starlette builds the stack lazily.

Warning texts:

  • 0.4.0: explicit login()/logout() that always rotate the session ID, and __Host- cookie by default #256: 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).
  • 0.4.0: explicit login()/logout() that always rotate the session ID, and __Host- cookie by default #256 prefixes: 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.
  • 0.4.0: enable get_or_set() stampede protection by default #280: 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).
  • 0.4.0: resolve get_session_manager through SessionManagerProxy #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).
  • 0.4.0: drop the Redis encoding option 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 with RedisConfig(encoding=...) for load_from_config)

Decisions

Docs

  • docs/MIGRATING_0_4.md and i18n/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 (login keep=, 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.
  • Guide updates, mirrored in zh-TW:
    • SESSION: explicit cookie settings in the examples, SessionManagerProxy.set() in the basic and Redis examples, a "Cookie defaults change in 0.4.0" section, and a 0.4.0 note on get_session_manager.
    • APP_CACHE: explicit lock= in the examples and a "The default changes in 0.4.0" subsection.
    • JWT_CLAIMS: middleware configs use __Host-session.
    • BACKENDS: encoding dropped from the RedisConfig example.
    • README / index: get_or_set(..., lock=True).
  • Examples (app_cache.py, session_login.py, session_jwt.py) use the explicit forms, and tests/test_examples.py runs them under filterwarnings = error.

Changelog

  • Fragments: 256.deprecated.md, 256.deprecated.2.md, 280.deprecated.md, 131.deprecated.md, 126.deprecated.md, 129.deprecated.md.
  • The release notice under ## [Unreleased] links to https://fastapi-cachex.readthedocs.io/en/stable/MIGRATING_0_4/. scripts/changelog_release.py --version 0.3.9 --dry-run prints it first.
  • test_the_repository_changelog_can_be_released assumed the section opens with ###; it now allows the notice above the first heading.

Tests

Checks

  • Full pytest with 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.

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
allen0099 force-pushed the feat/352-0-4-0-deprecations branch from 1820876 to 80f2168 Compare September 29, 2026 08:17
@allen0099
allen0099 merged commit cc02756 into master Sep 29, 2026
12 checks passed
@allen0099
allen0099 deleted the feat/352-0-4-0-deprecations branch September 29, 2026 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warn about every 0.4.0 breaking change in 0.3.9, the last 0.3.x release

1 participant