@@ -413,7 +413,7 @@ def data_row_for_external_id(self, external_id) -> "DataRow":
413413 external_id )
414414 return data_rows [0 ]
415415
416- def export_data_rows (self , timeout_seconds = 120 ) -> Generator :
416+ def export_data_rows (self , timeout_seconds = 120 , include_metadata : bool = False ) -> Generator :
417417 """ Returns a generator that produces all data rows that are currently
418418 attached to this dataset.
419419
@@ -428,22 +428,23 @@ def export_data_rows(self, timeout_seconds=120) -> Generator:
428428 LabelboxError: if the export fails or is unable to download within the specified time.
429429 """
430430 id_param = "datasetId"
431- query_str = """mutation GetDatasetDataRowsExportUrlPyApi($%s: ID!)
432- {exportDatasetDataRows(data:{datasetId: $%s }) {downloadUrl createdAt status}}
433- """ % (id_param , id_param )
431+ metadata_param = "includeMetadataInput"
432+ query_str = """mutation GetDatasetDataRowsExportUrlPyApi($%s: ID!, $%s: Boolean!)
433+ {exportDatasetDataRows(data:{datasetId: $%s , includeMetadataInput: $%s}) {downloadUrl createdAt status}}
434+ """ % (id_param , metadata_param , id_param , metadata_param )
434435 sleep_time = 2
435436 while True :
436- res = self .client .execute (query_str , {id_param : self .uid })
437+ res = self .client .execute (query_str , {id_param : self .uid , metadata_param : include_metadata })
437438 res = res ["exportDatasetDataRows" ]
438439 if res ["status" ] == "COMPLETE" :
439440 download_url = res ["downloadUrl" ]
440441 response = requests .get (download_url )
441442 response .raise_for_status ()
442443 reader = ndjson .reader (StringIO (response .text ))
443- # TODO: Update result to parse metadataFields when resolver returns
444444 return (Entity .DataRow (self .client , {
445- ** result , 'metadataFields' : [],
446- 'customMetadata' : []
445+ ** result ,
446+ 'customMetadata' : result ['metadata' ],
447+ 'metadataFields' : result ['metadataFields' ]
447448 }) for result in reader )
448449 elif res ["status" ] == "FAILED" :
449450 raise LabelboxError ("Data row export failed." )
@@ -457,3 +458,5 @@ def export_data_rows(self, timeout_seconds=120) -> Generator:
457458 logger .debug ("Dataset '%s' data row export, waiting for server..." ,
458459 self .uid )
459460 time .sleep (sleep_time )
461+
462+
0 commit comments