Skip to content

Commit

Permalink
check for id to set state to new or saved (#11735)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 5d39dc92832f5c20384b9f9cf48c8b448727ecbb
  • Loading branch information
philnugent authored and Descartes Labs Build committed Apr 12, 2023
1 parent 70a3c72 commit 18d1f37
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions descarteslabs/core/compute/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ def deserialize(cls, data: bytes):

class ComputeObject(object):
def __init__(self):
self._state = State.NEW
# check if object is new or persisted
if self.id:
self._state = State.SAVED
else:
self._state = State.NEW

def __setattr__(self, name, value):
super(ComputeObject, self).__setattr__("_state", State.MODIFIED)
Expand Down Expand Up @@ -136,7 +140,7 @@ def get(cls, id) -> "Job":
"""
client = ComputeClient.get_default_client()
response = client.session.get(f"/jobs/{id}")
return cls(**response.json(), _state=State.SAVED)
return cls(**response.json())

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

for data in paginator:
yield cls(**data, _state=State.SAVED)
yield cls(**data)

def refresh(self) -> None:
client = ComputeClient.get_default_client()
Expand Down Expand Up @@ -542,7 +546,7 @@ def get(cls, id: str):
"""
client = ComputeClient.get_default_client()
response = client.session.get(f"/functions/{id}")
return cls(**response.json(), _state=State.SAVED)
return cls(**response.json())

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

for data in paginator:
yield cls(**data, _state=State.SAVED)
yield cls(**data)

@property
def jobs(self) -> Iterable[Job]:
Expand Down

0 comments on commit 18d1f37

Please sign in to comment.