fix(etebase_fastapi): fix crash on shutdown (#133)

self.redis isn't None, it's actually unset, so accessing it results
in an exception:

```
ERROR:    Traceback (most recent call last):
  File "./.venv/lib/python3.9/site-packages/starlette/routing.py", line 624, in lifespan
    await receive()
  File "./.venv/lib/python3.9/site-packages/starlette/routing.py", line 521, in __aexit__
    await self._router.shutdown()
  File "./.venv/lib/python3.9/site-packages/starlette/routing.py", line 608, in shutdown
    await handler()
  File "./etebase_fastapi/main.py", line 72, in on_shutdown
    await redisw.close()
  File "./etebase_fastapi/redis.py", line 18, in close
    if self.redis is not None:
AttributeError: 'RedisWrapper' object has no attribute 'redis'
```
master
Xiretza 3 years ago committed by GitHub
parent 76efbb6cb9
commit b620d0a39c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -15,7 +15,7 @@ class RedisWrapper:
self.redis = await aioredis.create_redis_pool(self.redis_uri) self.redis = await aioredis.create_redis_pool(self.redis_uri)
async def close(self): async def close(self):
if self.redis is not None: if hasattr(self, "redis"):
self.redis.close() self.redis.close()
await self.redis.wait_closed() await self.redis.wait_closed()

Loading…
Cancel
Save