From 4ed098055705633acbc014c2a92690585c16cc07 Mon Sep 17 00:00:00 2001 From: Samuel Fendell Date: Fri, 29 Mar 2024 16:41:35 -0700 Subject: [PATCH] [PLT-51] Add error url for import test. --- labelbox/schema/task.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/labelbox/schema/task.py b/labelbox/schema/task.py index ed2a49a83..2382978e8 100644 --- a/labelbox/schema/task.py +++ b/labelbox/schema/task.py @@ -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 @@ -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, @@ -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"] @@ -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'