model: only pass "check_same_thread" arg for sqlite database (#1662)

This commit is contained in:
Masen Furer 2023-08-22 14:07:36 -07:00 committed by GitHub
parent 42e9924273
commit 196bdc5101
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,12 +43,9 @@ def get_engine(url: Optional[str] = None):
) )
# Print the SQL queries if the log level is INFO or lower. # Print the SQL queries if the log level is INFO or lower.
echo_db_query = os.environ.get("SQLALCHEMY_ECHO") == "True" echo_db_query = os.environ.get("SQLALCHEMY_ECHO") == "True"
return sqlmodel.create_engine( # Needed for the admin dash on sqlite.
url, connect_args = {"check_same_thread": False} if url.startswith("sqlite") else {}
echo=echo_db_query, return sqlmodel.create_engine(url, echo=echo_db_query, connect_args=connect_args)
# Needed for the admin dash.
connect_args={"check_same_thread": False},
)
class Model(Base, sqlmodel.SQLModel): class Model(Base, sqlmodel.SQLModel):