From 23fa6d5ec483ea5bafcd8875723b3c9bc98a4ac0 Mon Sep 17 00:00:00 2001 From: Mendie Uwemedimo <34003552+SlamChillz@users.noreply.github.com> Date: Wed, 19 Jul 2023 22:06:17 +0100 Subject: [PATCH] enable SQL statements echo with SQLALCHEMY_ECHO config constant for debugging (#1369) --- reflex/constants.py | 2 ++ reflex/model.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/reflex/constants.py b/reflex/constants.py index 1255e9674..51210fdce 100644 --- a/reflex/constants.py +++ b/reflex/constants.py @@ -124,6 +124,8 @@ RUN_BACKEND_PROD_WINDOWS = f"uvicorn --timeout-keep-alive {TIMEOUT}".split() # Socket.IO web server PING_INTERVAL = 25 PING_TIMEOUT = 120 +# flag to make the engine print all the SQL statements it executes +SQLALCHEMY_ECHO = get_value("SQLALCHEMY_ECHO", False, type_=bool) # Compiler variables. # The extension for compiled Javascript files. diff --git a/reflex/model.py b/reflex/model.py index 2575be3c6..121ebac4c 100644 --- a/reflex/model.py +++ b/reflex/model.py @@ -40,9 +40,12 @@ def get_engine(url: Optional[str] = None): console.print( "[red]Database is not initialized, run [bold]reflex db init[/bold] first." ) + echo_db_query = False + if conf.env == constants.Env.DEV and constants.SQLALCHEMY_ECHO: + echo_db_query = True return sqlmodel.create_engine( url, - echo=False, + echo=echo_db_query, connect_args={"check_same_thread": False} if conf.admin_dash else {}, )