diff --git a/antarest/core/tasks/model.py b/antarest/core/tasks/model.py index c18e205adb..996f4557d1 100644 --- a/antarest/core/tasks/model.py +++ b/antarest/core/tasks/model.py @@ -158,8 +158,15 @@ class TaskJob(Base): # type: ignore study: "Study" = relationship("Study", back_populates="jobs", uselist=False) def to_dto(self, with_logs: bool = False) -> TaskDTO: - assert self.result_status is not None - assert self.result_msg is not None + result = None + if self.completion_date: + assert self.result_status is not None + assert self.result_msg is not None + result = TaskResult( + success=self.result_status, + message=self.result_msg, + return_value=self.result, + ) return TaskDTO( id=self.id, owner=self.owner_id, @@ -167,13 +174,7 @@ def to_dto(self, with_logs: bool = False) -> TaskDTO: completion_date_utc=str(self.completion_date) if self.completion_date else None, name=self.name, status=TaskStatus(self.status), - result=TaskResult( - success=self.result_status, - message=self.result_msg, - return_value=self.result, - ) - if self.completion_date - else None, + result=result, logs=sorted([log.to_dto() for log in self.logs], key=lambda log: log.id) if with_logs else None, type=self.type, ref_id=self.ref_id,