diff --git a/src/taipy/core/__init__.py b/src/taipy/core/__init__.py index a51ad16a7..27bc7d49b 100644 --- a/src/taipy/core/__init__.py +++ b/src/taipy/core/__init__.py @@ -42,7 +42,7 @@ import os from ._core import Core -from .common.alias import CycleId, DataNodeId, JobId, PipelineId, ScenarioId, TaskId +from .common.alias import CycleId, DataNodeId, Edit, JobId, PipelineId, ScenarioId, TaskId from .common.default_custom_document import DefaultCustomDocument from .cycle.cycle import Cycle from .data.data_node import DataNode diff --git a/src/taipy/core/data/_data_manager.py b/src/taipy/core/data/_data_manager.py index 8024e69d4..c071ef4c1 100644 --- a/src/taipy/core/data/_data_manager.py +++ b/src/taipy/core/data/_data_manager.py @@ -12,7 +12,9 @@ import os from typing import Dict, Iterable, Optional, Set, Union +from taipy.config._config import _Config from taipy.config.common.scope import Scope +from taipy.config.config import Config from .._manager._manager import _Manager from .._version._version_manager_factory import _VersionManagerFactory @@ -75,7 +77,12 @@ def __create( version = _VersionManagerFactory._build_manager()._get_latest_version() props = data_node_config._properties.copy() validity_period = props.pop("validity_period", None) - return cls.__DATA_NODE_CLASS_MAP[data_node_config.storage_type]( # type: ignore + if data_node_config.storage_type: + storage_type = data_node_config.storage_type + else: + storage_type = Config.sections[DataNodeConfig.name][_Config.DEFAULT_KEY].storage_type + + return cls.__DATA_NODE_CLASS_MAP[storage_type]( # type: ignore config_id=data_node_config.id, scope=data_node_config.scope or DataNodeConfig._DEFAULT_SCOPE, owner_id=owner_id, diff --git a/tests/core/data/test_data_manager.py b/tests/core/data/test_data_manager.py index 7d6e70b27..3a4ae7c7c 100644 --- a/tests/core/data/test_data_manager.py +++ b/tests/core/data/test_data_manager.py @@ -23,6 +23,7 @@ from src.taipy.core.exceptions.exceptions import InvalidDataNodeType, ModelNotFound from taipy.config.common.scope import Scope from taipy.config.config import Config +from tests.core.utils.named_temporary_file import NamedTemporaryFile def file_exists(file_path: str) -> bool: @@ -451,3 +452,65 @@ def test_delete_does_clean_generated_pickle_files(self, pickle_file_path): _DataManager._delete_all() assert not file_exists(generated_pickle_dn_3.path) + + def test_create_dn_from_loaded_config_no_storage_type(self): + file_config = NamedTemporaryFile( + """ + [TAIPY] + [DATA_NODE.input] + scope = "SCENARIO:SCOPE" + default_data = "21:int" + [DATA_NODE.output] + storage_type = "in_memory" + scope = "SCENARIO:SCOPE" + [TASK.double] + inputs = [ "input:SECTION",] + function = "math.sqrt:function" + outputs = [ "output:SECTION",] + skippable = "False:bool" + [PIPELINE.my_pipeline] + tasks = [ "double:SECTION",] + [SCENARIO.my_scenario] + pipelines = [ "my_pipeline:SECTION",] + [SCENARIO.my_scenario.comparators] + """ + ) + from src.taipy import core as tp + + Config.load(file_config.filename) + scenario = tp.create_scenario(Config.scenarios["my_scenario"]) + + assert isinstance(scenario.input, PickleDataNode) + assert isinstance(scenario.output, InMemoryDataNode) + + def test_create_dn_from_loaded_config_modified_default_config(self): + file_config = NamedTemporaryFile( + """ + [TAIPY] + [DATA_NODE.input] + scope = "SCENARIO:SCOPE" + default_path="fake/path.csv" + default_data = "21:int" + [DATA_NODE.output] + storage_type = "in_memory" + scope = "SCENARIO:SCOPE" + [TASK.double] + inputs = [ "input:SECTION",] + function = "math.sqrt:function" + outputs = [ "output:SECTION",] + skippable = "False:bool" + [PIPELINE.my_pipeline] + tasks = [ "double:SECTION",] + [SCENARIO.my_scenario] + pipelines = [ "my_pipeline:SECTION",] + [SCENARIO.my_scenario.comparators] + """ + ) + from src.taipy import core as tp + + Config.load(file_config.filename) + Config.configure_default_data_node(storage_type="csv") + scenario = tp.create_scenario(Config.scenarios["my_scenario"]) + + assert isinstance(scenario.input, CSVDataNode) + assert isinstance(scenario.output, InMemoryDataNode)