From 6f80e5a0a6d46a31b408f38c93b680515562c1cc Mon Sep 17 00:00:00 2001
From: belthlemar <martin.belthle@rte-france.com>
Date: Thu, 29 Aug 2024 15:09:29 +0200
Subject: [PATCH] fix issue of none assertion

---
 antarest/core/tasks/model.py | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

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,