Open Thytu opened 3 months ago
Update: I found this temporary fix, however I'll obviously need to find a better option :D
@app.middleware("http")
async def add_process_time_header(request: Request, call_next):
await init_db() # already in the previous snippet
response = await call_next(request)
await Tortoise.close_connections() # Now also close the session after each call
return response
Describe the bug Tortoise seems to crash when used with Vercel (and probably any serverless service) + FastAPI.
When using
tortoise-orm
with FastAPI and Vercel, tortoise cannot manage to fetch the database connection resulting in the following error:To Reproduce Here is the code-snippet to reproduce it:
Obviously, in order to reproduce the error one also needs to deploy it on Vercel :)
Expected behavior I would expect tortoise to use previously initialized connection to return every elements of
SomeTable
.Additional context Note that in order to debug I also tried the following, which also results in a crash. However this time it crashs at the second call to the database as it tried to close an event loop that no-longer exists, resulting in a
RuntimeError('Event loop is closed')
error.