diff --git a/reflex/model.py b/reflex/model.py index acfa8779882..0ae874a8a39 100644 --- a/reflex/model.py +++ b/reflex/model.py @@ -111,7 +111,8 @@ def get_engine(url: str | None = None) -> sqlalchemy.engine.Engine: if not environment.ALEMBIC_CONFIG.get().exists(): console.warn( - "Database is not initialized, run [bold]reflex db init[/bold] first." + "Database is not initialized, run [bold]reflex db init[/bold] first.", + dedupe=True, ) _ENGINE[url] = sqlalchemy.engine.create_engine( url, @@ -153,7 +154,8 @@ def get_async_engine(url: str | None) -> sqlalchemy.ext.asyncio.AsyncEngine: if not environment.ALEMBIC_CONFIG.get().exists(): console.warn( - "Database is not initialized, run [bold]reflex db init[/bold] first." + "Database is not initialized, run [bold]reflex db init[/bold] first.", + dedupe=True, ) _ASYNC_ENGINE[url] = sqlalchemy.ext.asyncio.create_async_engine( url, @@ -316,8 +318,12 @@ def get_db_status() -> dict[str, bool]: engine = get_engine() with engine.connect() as connection: connection.execute(sqlalchemy.text("SELECT 1")) - except sqlalchemy.exc.OperationalError: + except Exception as exc: status = False + console.error( + f"Database health check failed: {exc} (subsequent errors will not be logged)", + dedupe=True, + ) return {"db": status} diff --git a/reflex/utils/prerequisites.py b/reflex/utils/prerequisites.py index 886d1dead96..6e9353d9633 100644 --- a/reflex/utils/prerequisites.py +++ b/reflex/utils/prerequisites.py @@ -431,8 +431,6 @@ async def get_redis_status() -> dict[str, bool | None]: Returns: The status of the Redis connection. """ - from redis.exceptions import RedisError - try: status = True redis_client = get_redis() @@ -442,8 +440,12 @@ async def get_redis_status() -> dict[str, bool | None]: await ping_command else: status = None - except RedisError: + except Exception as exc: status = False + console.error( + f"Redis health check failed: {exc} (subsequent errors will not be logged)", + dedupe=True, + ) return {"redis": status} @@ -645,7 +647,8 @@ def check_db_initialized() -> bool: and not environment.ALEMBIC_CONFIG.get().exists() ): console.error( - "Database is not initialized. Run [bold]reflex db init[/bold] first." + "Database is not initialized. Run [bold]reflex db init[/bold] first.", + dedupe=True, ) return False return True