@@ -39,6 +39,7 @@ class Task(DbObject):
3939 status = Field .String ("status" )
4040 completion_percentage = Field .Float ("completion_percentage" )
4141 result_url = Field .String ("result_url" , "result" )
42+ type = Field .String ("type" )
4243 _user : Optional ["User" ] = None
4344
4445 # Relationships
@@ -100,14 +101,15 @@ def result(self) -> Union[List[Dict[str, Any]], Dict[str, Any]]:
100101 raise ValueError (f"Job failed. Errors : { self .errors } " )
101102 else :
102103 result = self ._fetch_remote_json ()
103- if 'createdDataRows' in result :
104- return [{
105- 'id' : data_row ['id' ],
106- 'external_id' : data_row .get ('externalId' ),
107- 'row_data' : data_row ['rowData' ],
108- 'global_key' : data_row .get ('globalKey' ),
109- } for data_row in result ['createdDataRows' ]]
110- return result
104+ if self .type == 'export-data-rows' :
105+ return result
106+
107+ return [{
108+ 'id' : data_row ['id' ],
109+ 'external_id' : data_row .get ('externalId' ),
110+ 'row_data' : data_row ['rowData' ],
111+ 'global_key' : data_row .get ('globalKey' ),
112+ } for data_row in result ['createdDataRows' ]]
111113
112114 @property
113115 def failed_data_rows (self ) -> Optional [Dict [str , Any ]]:
@@ -134,9 +136,13 @@ def download_result():
134136 try :
135137 return ndjson .loads (response .text )
136138 except Exception as e :
137- raise ValueError (
138- "Unable to parse JSON or NDJSON. Please contact support for more details. Download task.result_url manually to access the result for other tasks."
139- )
139+ raise ValueError ("Failed to parse task JSON/NDJSON result." )
140+
141+ if self .name != 'JSON Import' and self .type != 'export-data-rows' :
142+ raise ValueError (
143+ "Task result is only supported for `JSON Import` and `export` tasks."
144+ " Download task.result_url manually to access the result for other tasks."
145+ )
140146
141147 if self .status != "IN_PROGRESS" :
142148 return download_result ()
0 commit comments