Skip to content

Commit

Permalink
fix: task config checker should check for scenario attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
trgiangdo committed Dec 20, 2023
1 parent 8ffaf96 commit 1f38b2b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
23 changes: 14 additions & 9 deletions taipy/core/config/checkers/_task_config_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand Down
18 changes: 11 additions & 7 deletions tests/core/config/checkers/test_task_config_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 1f38b2b

Please sign in to comment.