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.,:
@property
def session(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" not in self.scope or self.scope["session"] is Empty: # <---- add this "or" clause
raise ImproperlyConfiguredException(
"'session' is not defined in scope, install a SessionMiddleware to set it"
)
return cast("dict[str, Any]", self.scope["session"])
Originally posted by @peterschutt in #2427 (comment)
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too