mirror of
https://github.com/apache/superset.git
synced 2026-07-16 19:55:39 +00:00
refactor: begin transaction to automatically commit (#41979)
Co-authored-by: Evan Rusackas <evan@preset.io>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user