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

Master/Slave Setup Question #252

@shawnwall

Description

@shawnwall

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions