You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If setting scope["session"] to Empty is the same as the session not being set, then perhaps we should change ASGIConnection.session to raise if it is accessed when scope["session"] == Empty. At least that way we are sure to honor the type of the property. E.g.,:
@propertydefsession(self) ->dict[str, Any]:
"""Return the session for this connection if a session was previously set in the ``Scope`` Returns: A dictionary representing the session value - if existing. Raises: ImproperlyConfiguredException: if session is not set in scope. """if"session"notinself.scopeorself.scope["session"] isEmpty: # <---- add this "or" clauseraiseImproperlyConfiguredException(
"'session' is not defined in scope, install a SessionMiddleware to set it"
)
returncast("dict[str, Any]", self.scope["session"])
Property is typed to return `dict[str, Any]` but we use `Empty` as a sentinel to instruct session middleware to clear the session.
This PR changes the behavior of `ASGIConnection.session` to raise an exception on session access, just as if the session key is not set at all.
In addition, includes some related refactorings:
- Defines a new constant, `SCOPE_SESSION_KEY: Final = "session"` and replaces uses of `"session"` literal with that.
- Refactors tests/unit/test_connection/test_base.py to utilise fixtures.
Closes#2435
If setting
scope["session"]
toEmpty
is the same as the session not being set, then perhaps we should changeASGIConnection.session
to raise if it is accessed whenscope["session"] == Empty
. At least that way we are sure to honor the type of the property. E.g.,:Originally posted by @peterschutt in #2427 (comment)
Note
Check out all issues funded or available for funding here: https://polar.sh/litestar-org
The text was updated successfully, but these errors were encountered: