diff --git a/src/taipy/core/_repository/db/_sql_connection.py b/src/taipy/core/_repository/db/_sql_connection.py index 1cad4c1b..1e19e137 100644 --- a/src/taipy/core/_repository/db/_sql_connection.py +++ b/src/taipy/core/_repository/db/_sql_connection.py @@ -21,23 +21,23 @@ from ...exceptions import MissingRequiredProperty +def dict_factory(cursor, row): + d = {} + for idx, col in enumerate(cursor.description): + d[col[0]] = row[idx] + return d + + class _SQLConnection: _connection = None - @classmethod - def dict_factory(cls, cursor, row): - d = {} - for idx, col in enumerate(cursor.description): - d[col[0]] = row[idx] - return d - @classmethod def init_db(cls): if cls._connection: return cls._connection cls._connection = _build_connection() - cls._connection.row_factory = cls.dict_factory + cls._connection.row_factory = dict_factory from ..._version._version_model import _VersionModel from ...cycle._cycle_model import _CycleModel @@ -68,7 +68,6 @@ def init_db(cls): return cls._connection -@lru_cache def _build_connection() -> Connection: # Set SQLite threading mode to Serialized, means that threads may share the module, connections and cursors sqlite3.threadsafety = 3 diff --git a/tests/conftest.py b/tests/conftest.py index aa44b167..ca68d5e7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -23,7 +23,7 @@ from src.taipy.core._core import Core from src.taipy.core._orchestrator._orchestrator_factory import _OrchestratorFactory -from src.taipy.core._repository.db._sql_connection import _build_connection +from src.taipy.core._repository.db._sql_connection import _build_connection, _SQLConnection from src.taipy.core._version._version import _Version from src.taipy.core._version._version_manager_factory import _VersionManagerFactory from src.taipy.core._version._version_model import _VersionModel @@ -445,7 +445,8 @@ def init_sql_repo(tmp_sqlite): Config.configure_core(repository_type="sql", repository_properties={"db_location": tmp_sqlite}) # Clean SQLite database - connection = _build_connection() + _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()))) connection.execute(str(DropTable(_JobModel.__table__, if_exists=True).compile(dialect=sqlite.dialect()))) diff --git a/tests/core/job/test_job_manager_with_sql_repo.py b/tests/core/job/test_job_manager_with_sql_repo.py index 281695a7..9fdafe52 100644 --- a/tests/core/job/test_job_manager_with_sql_repo.py +++ b/tests/core/job/test_job_manager_with_sql_repo.py @@ -52,11 +52,6 @@ def init_managers(): _JobManagerFactory._build_manager()._delete_all() -def clear_sql_session(): - _build_connection.cache_clear() - _SQLConnection._connection = None - - def test_create_jobs(init_sql_repo): Config.configure_job_executions(mode=JobConfig._DEVELOPMENT_MODE) init_managers() @@ -165,8 +160,6 @@ def test_delete_job(init_sql_repo): def test_raise_when_trying_to_delete_unfinished_job(init_sql_repo): - clear_sql_session() - Config.configure_job_executions(mode=JobConfig._STANDALONE_MODE, max_nb_of_workers=2) init_managers() @@ -196,8 +189,6 @@ def test_raise_when_trying_to_delete_unfinished_job(init_sql_repo): def test_force_deleting_unfinished_job(init_sql_repo): - clear_sql_session() - Config.configure_job_executions(mode=JobConfig._STANDALONE_MODE, max_nb_of_workers=2) init_managers()