From b63110e2cb844fb27f7f1d93b4d3a506498ba24a Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Thu, 5 Dec 2024 22:13:09 -0800 Subject: [PATCH] resolve the url first, so the key into _ENGINE is correct --- reflex/model.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/reflex/model.py b/reflex/model.py index 53588f5c3..15825884c 100644 --- a/reflex/model.py +++ b/reflex/model.py @@ -39,14 +39,15 @@ def get_engine(url: str | None = None) -> sqlalchemy.engine.Engine: Raises: ValueError: If the database url is None. """ - global _ENGINE - if url in _ENGINE: - return _ENGINE[url] - conf = get_config() url = url or conf.db_url if url is None: raise ValueError("No database url configured") + + global _ENGINE + if url in _ENGINE: + return _ENGINE[url] + if not environment.ALEMBIC_CONFIG.get().exists(): console.warn( "Database is not initialized, run [bold]reflex db init[/bold] first." @@ -74,14 +75,15 @@ def get_async_engine(url: str | None) -> sqlalchemy.engine.Engine: Raises: ValueError: If the async database url is None. """ - global _ASYNC_ENGINE - if url in _ASYNC_ENGINE: - return _ASYNC_ENGINE[url] - conf = get_config() url = url or conf.async_db_url if url is None: raise ValueError("No async database url configured") + + global _ASYNC_ENGINE + if url in _ASYNC_ENGINE: + return _ASYNC_ENGINE[url] + if not environment.ALEMBIC_CONFIG.get().exists(): console.warn( "Database is not initialized, run [bold]reflex db init[/bold] first."