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

Code before:

        return _sequences

    @classmethod
    def _create(
        cls,
        sequence_name: str,
        tasks: Union[List[Task], List[TaskId]],
        subscribers: Optional[List[_Subscriber]] = None,
        properties: Optional[Dict] = None,
        scenario_id: Optional[ScenarioId] = None,
        version: Optional[str] = None,
    ) -> Sequence:
        task_manager = _TaskManagerFactory._build_manager()
        _tasks = cls.__get_sequence_tasks(tasks)

        sequence = cls._build_sequence(sequence_name, _tasks, subscribers, properties, scenario_id, version)
        sequence_id = sequence.id

        for task in _tasks:
            if sequence_id not in task._parent_ids:
                task._parent_ids.update([sequence_id])
                task_manager._set(task)

        if not sequence._is_consistent():
            raise InvalidSequence(sequence.id)

        return sequence

    @classmethod
    def _breakdown_sequence_id(cls, sequence_id: str) -> Tuple[str, str]:
        try:
            sequence_name, scenario_id = sequence_id.split(Scenario._ID_PREFIX)
            scenario_id = f"{Scenario._ID_PREFIX}{scenario_id}"
            sequence_name = sequence_name.split(Sequence._ID_PREFIX)[1].strip("_")
            sequence_name = sequence_name.replace("TPSPACE", " ")
            return sequence_name, scenario_id
        except (ValueError, IndexError):
            cls._logger.error(f"SequenceId {sequence_id} is invalid.")
            raise InvalidSequenceId(sequence_id) from None

    @classmethod
    def _get(cls, sequence: Union[str, Sequence], default=None) -> Sequence:
        """
        Returns a Sequence by id or reference.
        """
        try:
            sequence_id = sequence.id if isinstance(sequence, Sequence) else sequence
            sequence_name, scenario_id = cls._breakdown_sequence_id(sequence_id)

            scenario_manager = _ScenarioManagerFactory._build_manager()

Review comment (suggestion):
```suggestion
            raise InvalidSequence(sequence_id)
```

Code after:
            Notifier.publish(_make_event(sequence, EventOperation.CREATION))

        return _sequences

    @classmethod
    def _create(
        cls,
        sequence_name: str,
        tasks: Union[List[Task], List[TaskId]],
        subscribers: Optional[List[_Subscriber]] = None,
        properties: Optional[Dict] = None,
        scenario_id: Optional[ScenarioId] = None,
        version: Optional[str] = None,
    ) -> Sequence:
        task_manager = _TaskManagerFactory._build_manager()
        _tasks = cls.__get_sequence_tasks(tasks)

        sequence = cls._build_sequence(sequence_name, _tasks, subscribers, properties, scenario_id, version)
        sequence_id = sequence.id

        for task in _tasks:
            if sequence_id not in task._parent_ids:
                task._parent_ids.update([sequence_id])
                task_manager._set(task)

        if not sequence._is_consistent():
            raise InvalidSequence(sequence_id)

        return sequence

    @classmethod
    def _breakdown_sequence_id(cls, sequence_id: str) -> Tuple[str, str]:
        try:
            sequence_name, scenario_id = sequence_id.split(Scenario._ID_PREFIX)
            scenario_id = f"{Scenario._ID_PREFIX}{scenario_id}"
            sequence_name = sequence_name.split(Sequence._ID_PREFIX)[1].strip("_")
            sequence_name = sequence_name.replace("TPSPACE", " ")
            return sequence_name, scenario_id
        except (ValueError, IndexError):
            cls._logger.error(f"SequenceId {sequence_id} is invalid.")
            raise InvalidSequenceId(sequence_id) from None

    @classmethod
    def _get(cls, sequence: Union[str, Sequence], default=None) -> Sequence:
        """
        Returns a Sequence by id or reference.
        """
        try:
            sequence_id = sequence.id if isinstance(sequence, Sequence) else sequence
            sequence_name, scenario_id = cls._breakdown_sequence_id(sequence_id)