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

Code before:
    """
    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 is_sorted:
        if sort_key in ["name", "config_id", "creation_date", "tags"]:
            if sort_key == "tags":
                scenarios.sort(key=lambda x: (tuple(sorted(x.tags)), x.id), reverse=descending)
            else:
                scenarios.sort(key=lambda x: (getattr(x, sort_key), x.id), reverse=descending)
        elif sort_key == "id":
            scenarios.sort(key=lambda x: x.id, reverse=descending)
        else:
            scenarios.sort(key=lambda x: (x.name, x.id), reverse=descending)

    return scenarios


def get_primary(cycle: Cycle) -> Optional[Scenario]:
    """Retrieve the primary scenario associated with a cycle.

    Parameters:
        cycle (Cycle^): The cycle for which to retrieve the primary scenario.

    Returns:
        The primary scenario of the given _cycle_. If the cycle has no
            primary scenario, this method returns None.
    """
    return _ScenarioManagerFactory._build_manager()._get_primary(cycle)


def get_primary_scenarios(
    sorted: Optional[bool] = False, sort_key: Optional[Literal["name", "id", "creation_date", "tags"]] = "name"
) -> List[Scenario]:
    """Retrieve a list of all primary scenarios.

    Parameters:
         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.


Review comment (suggestion):
I suspect you wanted to use the following instead:

```suggestion
    if is_sorted:
        scenario_manager._sort_scenarios(scenarios, descending, sort_key)
    return scenarios
```


Code after:
            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 = []

    if is_sorted:
        scenario_manager._sort_scenarios(scenarios, descending, sort_key)
    return scenarios


def get_primary(cycle: Cycle) -> Optional[Scenario]:
    """Retrieve the primary scenario associated with a cycle.

    Parameters:
        cycle (Cycle^): The cycle for which to retrieve the primary scenario.

    Returns:
        The primary scenario of the given _cycle_. If the cycle has no
            primary scenario, this method returns None.
    """
    return _ScenarioManagerFactory._build_manager()._get_primary(cycle)


def get_primary_scenarios(
    is_sorted: bool = False,
    descending: bool = False,
    sort_key: Literal["name", "id", "config_id", "creation_date", "tags"] = "name",
) -> List[Scenario]:
    """Retrieve a list of all primary scenarios.

    Parameters:
         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 containing all primary scenarios, optionally sorted by name, id, creation_date or tags.
            The sorting is in increasing order for dates, in alphabetical order for name and