refactor: begin transaction to automatically commit (#41979)

Co-authored-by: Evan Rusackas <evan@preset.io>
This commit is contained in:
Hans Yu
2026-07-14 07:45:40 +02:00
committed by GitHub
parent 8afad27c84
commit e165762bb7
7 changed files with 102 additions and 89 deletions

View File

@@ -121,12 +121,13 @@ def test_time_grain_expressions(dttm: str, grain: str, expected: str) -> None:
from superset.db_engine_specs.sqlite import SqliteEngineSpec
engine = create_engine("sqlite://")
connection = engine.connect()
connection.execute(text("CREATE TABLE t (dttm DATETIME)"))
connection.execute(text("INSERT INTO t VALUES (:dttm)"), {"dttm": dttm})
with engine.begin() as connection:
connection.execute(text("CREATE TABLE t (dttm DATETIME)"))
connection.execute(text("INSERT INTO t VALUES (:dttm)"), {"dttm": dttm})
# pylint: disable=protected-access
expression = SqliteEngineSpec._time_grain_expressions[grain].format(col="dttm")
sql = f"SELECT {expression} FROM t" # noqa: S608
result = connection.execute(text(sql)).scalar()
with engine.connect() as connection:
result = connection.execute(text(sql)).scalar()
assert result == expected