Skip to content

Commit 18d1f37

Browse files
philnugentDescartes Labs Build
authored andcommitted
check for id to set state to new or saved (#11735)
GitOrigin-RevId: 5d39dc92832f5c20384b9f9cf48c8b448727ecbb
1 parent 70a3c72 commit 18d1f37

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

descarteslabs/core/compute/compute.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ def deserialize(cls, data: bytes):
5050

5151
class ComputeObject(object):
5252
def __init__(self):
53-
self._state = State.NEW
53+
# check if object is new or persisted
54+
if self.id:
55+
self._state = State.SAVED
56+
else:
57+
self._state = State.NEW
5458

5559
def __setattr__(self, name, value):
5660
super(ComputeObject, self).__setattr__("_state", State.MODIFIED)
@@ -136,7 +140,7 @@ def get(cls, id) -> "Job":
136140
"""
137141
client = ComputeClient.get_default_client()
138142
response = client.session.get(f"/jobs/{id}")
139-
return cls(**response.json(), _state=State.SAVED)
143+
return cls(**response.json())
140144

141145
@classmethod
142146
def list(cls, function_id, page_size=100) -> Iterable["Job"]:
@@ -160,7 +164,7 @@ def list(cls, function_id, page_size=100) -> Iterable["Job"]:
160164
paginator = client.paginate(f"/functions/{function_id}/jobs", params=params)
161165

162166
for data in paginator:
163-
yield cls(**data, _state=State.SAVED)
167+
yield cls(**data)
164168

165169
def refresh(self) -> None:
166170
client = ComputeClient.get_default_client()
@@ -542,7 +546,7 @@ def get(cls, id: str):
542546
"""
543547
client = ComputeClient.get_default_client()
544548
response = client.session.get(f"/functions/{id}")
545-
return cls(**response.json(), _state=State.SAVED)
549+
return cls(**response.json())
546550

547551
@classmethod
548552
def list(cls, status=None, page_size=100):
@@ -565,7 +569,7 @@ def list(cls, status=None, page_size=100):
565569
paginator = client.paginate("/functions", params=params)
566570

567571
for data in paginator:
568-
yield cls(**data, _state=State.SAVED)
572+
yield cls(**data)
569573

570574
@property
571575
def jobs(self) -> Iterable[Job]:

0 commit comments

Comments
 (0)