Skip to content

Commit

Permalink
fix: datanode config checker should check for task and scenario attri…
Browse files Browse the repository at this point in the history
…butes
  • Loading branch information
trgiangdo committed Dec 20, 2023
1 parent 82ee5dd commit 8ffaf96
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 27 deletions.
36 changes: 26 additions & 10 deletions taipy/core/config/checkers/_data_node_config_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
# specific language governing permissions and limitations under the License.

from datetime import timedelta
from typing import Dict
from typing import Dict, List

from taipy.config._config import _Config
from taipy.config.checker._checker import _ConfigChecker
from taipy.config.checker.issue_collector import IssueCollector
from taipy.config.common.scope import Scope

from ...data.data_node import DataNode
from ...scenario.scenario import Scenario
from ...task.task import Task
from ..data_node_config import DataNodeConfig


Expand All @@ -27,10 +28,17 @@ def __init__(self, config: _Config, collector: IssueCollector):

def _check(self) -> IssueCollector:
data_node_configs: Dict[str, DataNodeConfig] = self._config._sections[DataNodeConfig.name]
task_attributes = [attr for attr in dir(Task) if not callable(getattr(Task, attr)) and not attr.startswith("_")]
scenario_attributes = [
attr for attr in dir(Scenario) if not callable(getattr(Scenario, attr)) and not attr.startswith("_")
]

for data_node_config_id, data_node_config in data_node_configs.items():
self._check_existing_config_id(data_node_config)
self._check_if_entity_property_key_used_is_predefined(data_node_config)
self._check_if_config_id_is_overlapping_with_entity_attribute(data_node_config_id, data_node_config)
self._check_if_config_id_is_overlapping_with_task_and_scenario_attributes(
data_node_config_id, data_node_config, task_attributes, scenario_attributes
)
self._check_storage_type(data_node_config_id, data_node_config)
self._check_scope(data_node_config_id, data_node_config)
self._check_validity_period(data_node_config_id, data_node_config)
Expand All @@ -40,18 +48,26 @@ def _check(self) -> IssueCollector:
self._check_exposed_type(data_node_config_id, data_node_config)
return self._collector

def _check_if_config_id_is_overlapping_with_entity_attribute(
self, data_node_config_id: str, data_node_config: DataNodeConfig
def _check_if_config_id_is_overlapping_with_task_and_scenario_attributes(
self,
data_node_config_id: str,
data_node_config: DataNodeConfig,
task_attributes: List[str],
scenario_attributes: List[str],
):
entity_attributes = [
attr for attr in dir(DataNode) if not callable(getattr(DataNode, attr)) and not attr.startswith("_")
]
if data_node_config.id in entity_attributes:
if data_node_config.id in task_attributes:
self._error(
data_node_config._ID_KEY,
data_node_config.id,
f"The id of the DataNodeConfig `{data_node_config_id}` is overlapping with the "
f"attribute `{data_node_config.id}` of a Task entity.",
)
elif data_node_config.id in scenario_attributes:
self._error(
data_node_config._ID_KEY,
data_node_config.id,
f"The id of the DataNodeConfig `{data_node_config_id}` is overlapping with the "
f"attribute `{data_node_config.id}` of a DataNode entity.",
f"attribute `{data_node_config.id}` of a Scenario entity.",
)

def _check_storage_type(self, data_node_config_id: str, data_node_config: DataNodeConfig):
Expand Down
34 changes: 17 additions & 17 deletions tests/core/config/checkers/test_data_node_config_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_check_config_id(self, caplog):
Config.check()
assert len(Config._collector.errors) == 0

def test_check_config_id_is_different_from_all_datanode_properties(self, caplog):
def test_check_config_id_is_different_from_task_and_scenario_attributes(self, caplog):
Config._collector = IssueCollector()
config = Config._applied_config
Config._compile_configs()
Expand All @@ -55,24 +55,25 @@ def test_check_config_id_is_different_from_all_datanode_properties(self, caplog)
config._sections[DataNodeConfig.name]["new"] = copy(config._sections[DataNodeConfig.name]["default"])

for conflict_id in [
"cacheable",
"function",
"input",
"output",
"parent_ids",
"scope",
"skippable",
"additional_data_nodes",
"config_id",
"edit_in_progress",
"editor_expiration_date",
"editor_id",
"edits",
"expiration_date",
"is_ready_for_reading",
"is_up_to_date",
"is_valid",
"job_ids",
"last_edit_date",
"creation_date",
"cycle",
"data_nodes",
"is_primary",
"name",
"owner_id",
"parent_ids",
"properties",
"scope",
"validity_period",
"sequences",
"subscribers",
"tags",
"tasks",
"version",
]:
config._sections[DataNodeConfig.name]["new"].id = conflict_id
Expand All @@ -82,8 +83,7 @@ def test_check_config_id_is_different_from_all_datanode_properties(self, caplog)
Config.check()
assert len(Config._collector.errors) == 1
expected_error_message = (
"The id of the DataNodeConfig `new` is overlapping with the attribute"
f" `{conflict_id}` of a DataNode entity."
f"The id of the DataNodeConfig `new` is overlapping with the attribute `{conflict_id}` of a"
)
assert expected_error_message in caplog.text

Expand Down

0 comments on commit 8ffaf96

Please sign in to comment.