docs(session): align session docs and docstrings with the code - #360
Merged
Merged
Conversation
This was referenced Sep 29, 2026
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.
Docs/docstring accuracy audit of the session subsystem:
fastapi_cachex/session/docstrings and comments,docs/SESSION.md,docs/JWT_CLAIMS.mdand their zh-TW mirrors. Documentation only; the AST check confirms the.pychanges touch docstrings and comments only.Corrections
Set-Cookie. In the code the transport depends on whether the request sent a header/bearer token, even one that no longer resolves. If it did, the new session's token goes back in theheader_nameresponse header.SessionMiddlewarealso sends a token for a regenerated ID, not only a renewed one.Basic Usagemodel isCredentials(examples/session_api.py), but two snippets referred to aLoginRequestmodel from that section.InsecureKeyLengthWarningonly in 2.11 and later. The declared floor is 2.9.0, which does not have it (checked against 2.9.0, 2.10.1, 2.11.0 and the latest release).expor a wrongiss/audraisesSessionTokenError.SessionSecurityErrorcovers only a badsimplesignature or a binding mismatch.FutureWarningfires when the middleware is constructed, when the app builds its middleware stack, not atadd_middleware(). Also,cookie_max_age=0omitsMax-Agejust asNonedoes.Set-Cookiefor a cookie), not always in theheader_nameheader.JWTTokenSerializersaidexpis derived fromsession_ttl. It is the session'sexpires_at, withiat + session_ttlonly as a fallback.JWTTokenSerializer.__init__,from_string,SessionManager.__init__, and the__init__of both middlewares.SessionManager.get_sessionRaises now matches the real split betweenSessionTokenErrorandSessionSecurityError, and says an expired session is saved asEXPIRED.get_session_manager'sFutureWarningalso fires when the proxy holds no manager._write_sessionalso runs for a user session emptied withdel/pop.FastAPICacheXSessionMiddlewareclass docstring now covers the header/bearer transport.create_anonymous_session.ValueErrorcontract toTokenSerializer.from_string.Possible code issues (not changed)
fastapi_cachex/session/middleware.py:656-660:cookie_max_age=0(and negative values, which are not validated) is treated likeNonebecause of a truthiness check. The field description says onlyNonedisablesMax-Age.fastapi_cachex/session/config.py:88-91: thesliding_expirationfield description reads "refresh session expiry on each access". Renewal only happens once less thansession_ttl * sliding_thresholdremains. This is a code string, so it was left alone.