feat: harden multi-host runtime coordination

This commit is contained in:
2026-08-02 05:30:11 +02:00
parent b58c9c55cf
commit d6255f9f8f
7 changed files with 92 additions and 7 deletions
+6 -1
View File
@@ -91,7 +91,12 @@ _default_database: DatabaseHandle | None = None
def configure_database(database_url: str, *, engine: Engine | None = None, dispose_previous: bool = False) -> DatabaseHandle:
global _default_database
if engine is None and _default_database is not None and _default_database.database_url == database_url:
if (
engine is None
and not dispose_previous
and _default_database is not None
and _default_database.database_url == database_url
):
return _default_database
previous_database = _default_database
_default_database = DatabaseHandle(database_url, engine=engine)