Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions labelbox/schema/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class Task(DbObject):
created_by = Relationship.ToOne("User", False, "created_by")
organization = Relationship.ToOne("Organization")

# Import and upsert have several instances of special casing
def is_creation_task(self) -> bool:
return self.name == 'JSON Import' or self.type == 'adv-upsert-data-rows'

def refresh(self) -> None:
""" Refreshes Task data from the server. """
assert self._user is not None
Expand All @@ -57,6 +61,8 @@ def refresh(self) -> None:
raise ResourceNotFoundError(Task, self.uid)
for field in self.fields():
setattr(self, field.name, getattr(tasks[0], field.name))
if self.is_creation_task():
self.errors_url = self.result_url

def wait_till_done(self,
timeout_seconds: float = 300.0,
Expand Down Expand Up @@ -90,7 +96,7 @@ def wait_till_done(self,
def errors(self) -> Optional[Dict[str, Any]]:
""" Fetch the error associated with an import task.
"""
if self.name == 'JSON Import' or self.type == 'adv-upsert-data-rows':
if self.is_creation_task():
if self.status == "FAILED":
result = self._fetch_remote_json()
return result["error"]
Expand Down Expand Up @@ -168,7 +174,7 @@ def download_result(remote_json_field: Optional[str], format: str):
"Expected the result format to be either `ndjson` or `json`."
)

if self.name == 'JSON Import' or self.type == 'adv-upsert-data-rows':
if self.is_creation_task():
format = 'json'
elif self.type == 'export-data-rows':
format = 'ndjson'
Expand Down