Repository: Avaiga/taipy
File: taipy/core/taipy.py (Python)

Code before:
    if _is_data_node(entity_id):
        return _DataManagerFactory._build_manager()._delete(DataNodeId(entity_id))
    if _is_submission(entity_id):
        return _SubmissionManagerFactory._build_manager()._hard_delete(SubmissionId(entity_id))
    raise ModelNotFound("NOT_DETERMINED", entity_id)


def get_scenarios(
    cycle: Optional[Cycle] = None,
    tag: Optional[str] = None,
    sorted: Optional[bool] = False,
    sort_key: Optional[Literal["name", "id", "creation_date", "tags"]] = "name",
) -> List[Scenario]:
    """Retrieve a list of existing scenarios filtered by cycle or tag.

    This function allows you to retrieve a list of scenarios based on optional
    filtering criteria. If both a _cycle_ and a _tag_ are provided, the returned
    list contains scenarios that belong to the specified _cycle_ **and** also
    have the specified _tag_.

    Parameters:
         cycle (Optional[Cycle^]): The optional `Cycle^` to filter scenarios by.
         tag (Optional[str]): The optional tag to filter scenarios by.
         sorted (Optional[bool]): The option to sort scenarios. The default sorting key is name.
         sort_key (Optional[Literal["name", "id", "creation_date", "tags"]]): The optiononal sort_key to decide upon
         what key scenarios are sorted.

    Returns:
        The list of scenarios filtered by cycle or tag and optionally sorted by name, id, creation_date or tags.
        The sorting is in increasing order for dates, in alphabetical order for name and id
        and in lexographical order for tags.
        If no filtering criteria are provided, this method returns all existing scenarios.
        If sorted is set to true, but an incorrect or no sort_key is provided, then the scenarios are sorted by name.
    """
    scenario_manager = _ScenarioManagerFactory._build_manager()
    if not cycle and not tag:
        scenarios = scenario_manager._get_all()
    elif cycle and not tag:
        scenarios = scenario_manager._get_all_by_cycle(cycle)
    elif not cycle and tag:
        scenarios = scenario_manager._get_all_by_tag(tag)
    elif cycle and tag:
        cycles_scenarios = scenario_manager._get_all_by_cycle(cycle)
        scenarios = [scenario for scenario in cycles_scenarios if scenario.has_tag(tag)]
    else:
        scenarios = []

    if sorted:
        if sort_key in ["name", "id", "creation_date", "tags"]:
            scenarios.sort(key=lambda x: getattr(x, sort_key))
        else:

Review comment (suggestion):
```suggestion
         sorted (Optional[bool]): If True, the returned list of scenarios is sorted by the sorting key.
         The default value is False.
         sort_key (Optional[Literal["name", "id", "creation_date", "tags"]]): The optional sort_key to decide upon
         what key scenarios are sorted. The default sorting key is "name".
```

Code after:
        return _SequenceManagerFactory._build_manager()._hard_delete(SequenceId(entity_id))
    if _is_task(entity_id):
        return _TaskManagerFactory._build_manager()._hard_delete(TaskId(entity_id))
    if _is_data_node(entity_id):
        return _DataManagerFactory._build_manager()._delete(DataNodeId(entity_id))
    if _is_submission(entity_id):
        return _SubmissionManagerFactory._build_manager()._hard_delete(SubmissionId(entity_id))
    raise ModelNotFound("NOT_DETERMINED", entity_id)


def get_scenarios(
    cycle: Optional[Cycle] = None,
    tag: Optional[str] = None,
    is_sorted: bool = False,
    descending: bool = False,
    sort_key: Literal["name", "id", "config_id", "creation_date", "tags"] = "name",
) -> List[Scenario]:
    """Retrieve a list of existing scenarios filtered by cycle or tag.

    This function allows you to retrieve a list of scenarios based on optional
    filtering criteria. If both a _cycle_ and a _tag_ are provided, the returned
    list contains scenarios that belong to the specified _cycle_ **and** also
    have the specified _tag_.

    Parameters:
         cycle (Optional[Cycle^]): The optional `Cycle^` to filter scenarios by.
         tag (Optional[str]): The optional tag to filter scenarios by.
         is_sorted (bool): The option to sort scenarios. The default sorting key is name.
         descending (bool): The option to sort scenarios on the sorting key in descending order.
         sort_key (Literal["name", "id", "creation_date", "tags"]): The optiononal sort_key to
             decide upon what key scenarios are sorted. The sorting is in increasing order for
             dates, in alphabetical order for name and id, in lexographical order for tags.

    Returns:
        The list of scenarios filtered by cycle or tag and optionally sorted by name, id, creation_date or tags.
            If no filtering criterion is provided, this method returns all existing scenarios.
            If is_sorted is set to true, the scenarios are sorted by sort_key. The scenarios
            are sorted by name if an incorrect or no sort_key is provided.
    """
    scenario_manager = _ScenarioManagerFactory._build_manager()
    if not cycle and not tag:
        scenarios = scenario_manager._get_all()
    elif cycle and not tag:
        scenarios = scenario_manager._get_all_by_cycle(cycle)
    elif not cycle and tag:
        scenarios = scenario_manager._get_all_by_tag(tag)
    elif cycle and tag:
        cycles_scenarios = scenario_manager._get_all_by_cycle(cycle)
        scenarios = [scenario for scenario in cycles_scenarios if scenario.has_tag(tag)]
    else:
        scenarios = []