diff --git a/src/taipy/core/_repository/db/_sql_connection.py b/src/taipy/core/_repository/db/_sql_connection.py index 1e19e137..f01c7e04 100644 --- a/src/taipy/core/_repository/db/_sql_connection.py +++ b/src/taipy/core/_repository/db/_sql_connection.py @@ -78,5 +78,9 @@ def _build_connection() -> Connection: except KeyError: raise MissingRequiredProperty("Missing property db_location") - connection = sqlite3.connect(db_location, check_same_thread=False) - return connection + return __build_connection(db_location) + + +@lru_cache +def __build_connection(db_location: str): + return sqlite3.connect(db_location, check_same_thread=False) diff --git a/tests/conftest.py b/tests/conftest.py index ca68d5e7..b32e2ccc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -445,7 +445,9 @@ def init_sql_repo(tmp_sqlite): Config.configure_core(repository_type="sql", repository_properties={"db_location": tmp_sqlite}) # Clean SQLite database - _SQLConnection._connection = None + if _SQLConnection._connection: + _SQLConnection._connection.close() + _SQLConnection._connection = None connection = _SQLConnection.init_db() connection.execute(str(DropTable(_CycleModel.__table__, if_exists=True).compile(dialect=sqlite.dialect()))) connection.execute(str(DropTable(_DataNodeModel.__table__, if_exists=True).compile(dialect=sqlite.dialect())))