33from copy import deepcopy
44from enum import Enum
55from itertools import chain
6- from typing import List , Optional , Dict , Union , Callable , Type , Any , Generator
6+ import warnings
7+
8+ from typing import List , Optional , Dict , Union , Callable , Type , Any , Generator , overload
79
810from pydantic import BaseModel , conlist , constr
11+ from labelbox .schema .identifiables import DataRowIdentifiers , UniqueIds
912
1013from labelbox .schema .ontology import SchemaId
1114from labelbox .utils import _CamelCaseMixin , format_iso_datetime , format_iso_from_string
@@ -601,27 +604,44 @@ def _batch_delete(
601604 items ,
602605 batch_size = self ._batch_size )
603606
607+ @overload
604608 def bulk_export (self , data_row_ids : List [str ]) -> List [DataRowMetadata ]:
609+ pass
610+
611+ @overload
612+ def bulk_export (self ,
613+ data_row_ids : DataRowIdentifiers ) -> List [DataRowMetadata ]:
614+ pass
615+
616+ def bulk_export (self , data_row_ids ) -> List [DataRowMetadata ]:
605617 """ Exports metadata for a list of data rows
606618
607619 >>> mdo.bulk_export([data_row.uid for data_row in data_rows])
608620
609621 Args:
610- data_row_ids: List of data data rows to fetch metadata for
622+ data_row_ids: List of data data rows to fetch metadata for. This can be a list of strings or a DataRowIdentifiers object
623+ DataRowIdentifier objects are lists of ids or global keys. A DataIdentifier object can be a UniqueIds or GlobalKeys class.
611624 Returns:
612625 A list of DataRowMetadata.
613626 There will be one DataRowMetadata for each data_row_id passed in.
614627 This is true even if the data row does not have any meta data.
615628 Data rows without metadata will have empty `fields`.
616629
617630 """
618-
619631 if not len (data_row_ids ):
620632 raise ValueError ("Empty list passed" )
621633
622- def _bulk_export (_data_row_ids : List [str ]) -> List [DataRowMetadata ]:
623- query = """query dataRowCustomMetadataPyApi($dataRowIds: [ID!]!) {
624- dataRowCustomMetadata(where: {dataRowIds : $dataRowIds}) {
634+ if isinstance (data_row_ids ,
635+ list ) and len (data_row_ids ) > 0 and isinstance (
636+ data_row_ids [0 ], str ):
637+ data_row_ids = UniqueIds (data_row_ids )
638+ warnings .warn ("Using data row ids will be deprecated. Please use "
639+ "UniqueIds or GlobalKeys instead." )
640+
641+ def _bulk_export (
642+ _data_row_ids : DataRowIdentifiers ) -> List [DataRowMetadata ]:
643+ query = """query dataRowCustomMetadataPyApi($dataRowIdentifiers: DataRowCustomMetadataDataRowIdentifiersInput) {
644+ dataRowCustomMetadata(where: {dataRowIdentifiers : $dataRowIdentifiers}) {
625645 dataRowId
626646 globalKey
627647 fields {
@@ -633,8 +653,12 @@ def _bulk_export(_data_row_ids: List[str]) -> List[DataRowMetadata]:
633653 """
634654 return self .parse_metadata (
635655 self ._client .execute (
636- query ,
637- {"dataRowIds" : _data_row_ids })['dataRowCustomMetadata' ])
656+ query , {
657+ "dataRowIdentifiers" : {
658+ "ids" : [id for id in _data_row_ids ],
659+ "idType" : _data_row_ids .id_type
660+ }
661+ })['dataRowCustomMetadata' ])
638662
639663 return _batch_operations (_bulk_export ,
640664 data_row_ids ,
0 commit comments