11import logging
2- import json
32import requests
43import time
5- from typing import TYPE_CHECKING , TypeVar , Callable , Optional , Dict , Any , List
4+ from typing import TYPE_CHECKING , Callable , Optional , Dict , Any , List
65
76from labelbox .exceptions import ResourceNotFoundError
87from labelbox .orm .db_object import DbObject
@@ -64,7 +63,9 @@ def wait_till_done(self, timeout_seconds=300) -> None:
6463 check_frequency = 2 # frequency of checking, in seconds
6564 while True :
6665 if self .status != "IN_PROGRESS" :
67- if self .status == 'FAILED' :
66+ if self .status == "FAILED" or (self .status == "COMPLETE" and
67+ self .failed_data_rows
68+ is not None ):
6869 logger .warning (
6970 "There are errors present. Please look at `task.errors` for more details"
7071 )
@@ -80,16 +81,18 @@ def wait_till_done(self, timeout_seconds=300) -> None:
8081
8182 @property
8283 def errors (self ) -> Optional [Dict [str , Any ]]:
83- """ Downloads the result file from Task
84+ """ Fetch the error associated with an import task.
8485 """
8586 if self .status == "FAILED" :
8687 result = self ._fetch_remote_json ()
87- return result ['error' ]
88+ return result ["error" ]
89+ elif self .status == "COMPLETE" :
90+ return self .failed_data_rows ()
8891 return None
8992
9093 @property
9194 def result (self ) -> List [Dict [str , Any ]]:
92- """ Fetch the result for a task
95+ """ Fetch the result for an import task.
9396 """
9497 if self .status == "FAILED" :
9598 raise ValueError (f"Job failed. Errors : { self .errors } " )
@@ -102,6 +105,15 @@ def result(self) -> List[Dict[str, Any]]:
102105 'global_key' : data_row .get ('globalKey' ),
103106 } for data_row in result ['createdDataRows' ]]
104107
108+ def failed_data_rows (self ) -> Optional [Dict [str , Any ]]:
109+ """ Fetch data rows which failed to be created for an import task.
110+ """
111+ result = self ._fetch_remote_json ()
112+ if result .get ("errors" ) is not None :
113+ return result ["errors" ]
114+ else :
115+ return None
116+
105117 @lru_cache ()
106118 def _fetch_remote_json (self ) -> Dict [str , Any ]:
107119 """ Function for fetching and caching the result data.
0 commit comments