From 1f38b2b81bf939408581436f245e1a8f6b61e26b Mon Sep 17 00:00:00 2001 From: trgiangdo Date: Wed, 20 Dec 2023 14:12:02 +0700 Subject: [PATCH] fix: task config checker should check for scenario attributes --- .../config/checkers/_task_config_checker.py | 23 +++++++++++-------- .../checkers/test_task_config_checker.py | 18 +++++++++------ 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/taipy/core/config/checkers/_task_config_checker.py b/taipy/core/config/checkers/_task_config_checker.py index 20cde3dc57..dbedb35d6c 100644 --- a/taipy/core/config/checkers/_task_config_checker.py +++ b/taipy/core/config/checkers/_task_config_checker.py @@ -9,11 +9,13 @@ # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the # specific language governing permissions and limitations under the License. +from typing import List + from taipy.config._config import _Config from taipy.config.checker._checkers._config_checker import _ConfigChecker from taipy.config.checker.issue_collector import IssueCollector -from ...task.task import Task +from ...scenario.scenario import Scenario from ..data_node_config import DataNodeConfig from ..task_config import TaskConfig @@ -24,28 +26,31 @@ def __init__(self, config: _Config, collector: IssueCollector): def _check(self) -> IssueCollector: task_configs = self._config._sections[TaskConfig.name] + scenario_attributes = [ + attr for attr in dir(Scenario) if not callable(getattr(Scenario, attr)) and not attr.startswith("_") + ] + for task_config_id, task_config in task_configs.items(): if task_config_id != _Config.DEFAULT_KEY: self._check_existing_config_id(task_config) self._check_if_entity_property_key_used_is_predefined(task_config) - self._check_if_config_id_is_overlapping_with_entity_attribute(task_config_id, task_config) + self._check_if_config_id_is_overlapping_with_scenario_attributes( + task_config_id, task_config, scenario_attributes + ) self._check_existing_function(task_config_id, task_config) self._check_inputs(task_config_id, task_config) self._check_outputs(task_config_id, task_config) return self._collector - def _check_if_config_id_is_overlapping_with_entity_attribute( - self, task_config_id: str, task_config: DataNodeConfig + def _check_if_config_id_is_overlapping_with_scenario_attributes( + self, task_config_id: str, task_config: TaskConfig, scenario_attributes: List[str] ): - entity_attributes = [ - attr for attr in dir(Task) if not callable(getattr(Task, attr)) and not attr.startswith("_") - ] - if task_config.id in entity_attributes: + if task_config.id in scenario_attributes: self._error( task_config._ID_KEY, task_config.id, f"The id of the TaskConfig `{task_config_id}` is overlapping with the " - f"attribute `{task_config.id}` of a Task entity.", + f"attribute `{task_config.id}` of a Scenario entity.", ) def _check_inputs(self, task_config_id: str, task_config: TaskConfig): diff --git a/tests/core/config/checkers/test_task_config_checker.py b/tests/core/config/checkers/test_task_config_checker.py index b7187db85b..ddda827d82 100644 --- a/tests/core/config/checkers/test_task_config_checker.py +++ b/tests/core/config/checkers/test_task_config_checker.py @@ -59,16 +59,19 @@ def test_check_config_id_is_different_from_all_task_properties(self, caplog): config._sections[TaskConfig.name]["new"] = copy(config._sections[TaskConfig.name]["default"]) for conflict_id in [ + "additional_data_nodes", "config_id", + "creation_date", + "cycle", "data_nodes", - "function", - "input", - "output", + "is_primary", + "name", "owner_id", - "parent_ids", "properties", - "scope", - "skippable", + "sequences", + "subscribers", + "tags", + "tasks", "version", ]: config._sections[TaskConfig.name]["new"].id = conflict_id @@ -78,7 +81,8 @@ def test_check_config_id_is_different_from_all_task_properties(self, caplog): Config.check() assert len(Config._collector.errors) == 2 expected_error_message = ( - "The id of the TaskConfig `new` is overlapping with the attribute" f" `{conflict_id}` of a Task entity." + "The id of the TaskConfig `new` is overlapping with the attribute" + f" `{conflict_id}` of a Scenario entity." ) assert expected_error_message in caplog.text