Fix cached old Task ID causes session CLI to stop working due to APIError raised

This commit is contained in:
allegroai 2023-12-07 16:08:13 +02:00
parent c5242d5470
commit f228e085eb

View File

@ -21,7 +21,7 @@ else:
import psutil import psutil
from clearml import Task from clearml import Task
from clearml.backend_api.session.client import APIClient from clearml.backend_api.session.client import APIClient, APIError
from clearml.config import config_obj from clearml.config import config_obj
from clearml.backend_api import Session from clearml.backend_api import Session
from .tcp_proxy import TcpProxy from .tcp_proxy import TcpProxy
@ -322,6 +322,7 @@ def _get_running_tasks(client, prev_task_id):
tasks_id_created = [(t.id, t.created, t.parent) for t in previous_tasks] tasks_id_created = [(t.id, t.created, t.parent) for t in previous_tasks]
if prev_task_id and prev_task_id not in (t[0] for t in tasks_id_created): if prev_task_id and prev_task_id not in (t[0] for t in tasks_id_created):
# manually check the last task.id # manually check the last task.id
try:
prev_tasks = client.tasks.get_all(**{ prev_tasks = client.tasks.get_all(**{
'status': ['in_progress'], 'status': ['in_progress'],
'id': [prev_task_id], 'id': [prev_task_id],
@ -329,6 +330,10 @@ def _get_running_tasks(client, prev_task_id):
'order_by': ['-last_update'], 'order_by': ['-last_update'],
'only_fields': ['id', 'created', 'parent'] 'only_fields': ['id', 'created', 'parent']
}) })
except APIError:
# we could not find previous task, nothing to worry about.
prev_tasks = None
if prev_tasks: if prev_tasks:
tasks_id_created += [(prev_tasks[0].id, prev_tasks[0].created, prev_tasks[0].parent)] tasks_id_created += [(prev_tasks[0].id, prev_tasks[0].created, prev_tasks[0].parent)]