starlette-session
starlette-session copied to clipboard
Redis or Memcache backend key not found, request.session will be None
When redis or memcache clear the key/value data, session_backend.get() will return None. as the request.session will be None. None object cannot call update(). This bug happens when the redis server migrate to the new server with no data, but client brower send the original session key, then exception rasied. Looking into the code, on init.py line 80-96: `
connection = HTTPConnection(scope)
initial_session_was_empty = True
if self.cookie_name in connection.cookies:
data = connection.cookies[self.cookie_name].encode("utf-8")
try:
data = self.signer.unsign(data, max_age=self.max_age)
if self.backend_type == BackendType.cookie or not self.session_backend:
scope["session"] = json.loads(b64decode(data))
else:
session_key = json.loads(b64decode(data)).get(
self._cookie_session_id_field
)
scope["session"] = await self.session_backend.get(session_key)
scope["__session_key"] = session_key
######### SHOULD ADD THE CODE HERE
if scope["session“] == None:
scope["session"] = {}
################################
initial_session_was_empty = False
`
I've hit this too, it's quite serious it essentially makes the library unusable
@auredentan Is this project still being maintained? @gmmeyer's pull request looks good, but it's been open for quite a while.