This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Description
I'm not quite sure whether to post this question within starlette or here, but databases seems to be at the core of the issue.
My db setup involves a RDS (aws mariadb/mysql) cluster with a writer (master) and various readers (slaves). I'm attempting to write some services in starlette that read and write data. The documentation on both starlette and databases pushes us to try to use the startup and shutdown events for connect() and disconnect() to a single Database. Given I want to sometimes read, and sometimes write, always having connections around does not work unless I were to always connect and disconnect to both a reader and a writer.
I attempted to use the context manager approach instead in an endpoint via:
async with read_db as db:
# operations here
without even trying to use the writer yet, and I'm getting the following errors spitting out:
AssertionError: Already disconnected.
...when running under any type of local testing volume. So... my general question is, how should we approach this with databases and starlette?