Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #467 from Avaiga/hotfix/#464-error-mapping-storage…
Browse files Browse the repository at this point in the history
…-type-None

[hotfix2.1] fix error mapping storage type when is None to DATA_NODE_CLASS_MAP
  • Loading branch information
toan-quach authored Feb 8, 2023
2 parents 12e9d31 + ef084af commit cd7c10f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/taipy/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/taipy/core/data/_data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
63 changes: 63 additions & 0 deletions tests/core/data/test_data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)

0 comments on commit cd7c10f

Please sign in to comment.