Skip to content

Commit 3c95abf

Browse files
authored
Prevent crash when no previous deployment exists (#614)
1 parent e025fda commit 3c95abf

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

lean/components/util/live_utils.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from typing import Any, Dict, List, Optional
1818
from lean.components.api.api_client import APIClient
1919
from lean.components.util.logger import Logger
20+
from lean.models.errors import RequestFailedError
2021
from lean.models.json_module import LiveInitialStateInput, JsonModule
2122
from collections import UserDict
2223

@@ -41,13 +42,19 @@ def _get_last_portfolio(api_client: APIClient, project_id: str, project_name: Pa
4142
from datetime import datetime
4243

4344
cloud_last_time = utc.localize(datetime.min)
45+
4446
if project_id:
45-
cloud_deployment = api_client.get("live/read", {"projectId": project_id})
46-
if cloud_deployment["success"] and cloud_deployment["status"] != "Undefined":
47-
if cloud_deployment["stopped"] is not None:
48-
cloud_last_time = datetime.strptime(cloud_deployment["stopped"], "%Y-%m-%d %H:%M:%S")
49-
else:
50-
cloud_last_time = datetime.strptime(cloud_deployment["launched"], "%Y-%m-%d %H:%M:%S")
47+
try:
48+
cloud_deployment = api_client.get("live/read", {"projectId": project_id})
49+
if cloud_deployment["success"] and cloud_deployment["status"] != "Undefined":
50+
if cloud_deployment["stopped"] is not None:
51+
cloud_last_time = datetime.strptime(cloud_deployment["stopped"], "%Y-%m-%d %H:%M:%S")
52+
else:
53+
cloud_last_time = datetime.strptime(cloud_deployment["launched"], "%Y-%m-%d %H:%M:%S")
54+
except RequestFailedError as e:
55+
if "No live deployment found" not in str(e):
56+
raise
57+
5158
cloud_last_time = datetime(cloud_last_time.year, cloud_last_time.month,
5259
cloud_last_time.day, cloud_last_time.hour,
5360
cloud_last_time.minute,

0 commit comments

Comments
 (0)