11import logging
2+ from datetime import datetime
3+ from typing import List , Dict , Union
24
35from labelbox .orm import query
46from labelbox .orm .db_object import DbObject , Updateable , BulkDeletable
@@ -18,6 +20,7 @@ class DataRow(DbObject, Updateable, BulkDeletable):
1820 updated_at (datetime)
1921 created_at (datetime)
2022 media_attributes (dict): generated media attributes for the datarow
23+ metadata (dict): uploaded metadata
2124
2225 dataset (Relationship): `ToOne` relationship to Dataset
2326 created_by (Relationship): `ToOne` relationship to User
@@ -37,21 +40,45 @@ class DataRow(DbObject, Updateable, BulkDeletable):
3740 created_by = Relationship .ToOne ("User" , False , "created_by" )
3841 organization = Relationship .ToOne ("Organization" , False )
3942 labels = Relationship .ToMany ("Label" , True )
40-
41- metadata = Relationship .ToMany (
42- "AssetMetadata" ,
43- False ,
44- "metadata" ,
45- deprecation_warning =
46- "`DataRow.metadata()` is deprecated. Use `DataRow.attachments()` instead."
47- )
4843 attachments = Relationship .ToMany ("AssetAttachment" , False , "attachments" )
4944
5045 supported_meta_types = supported_attachment_types = {
5146 attachment_type .value
5247 for attachment_type in AssetAttachment .AttachmentType
5348 }
5449
50+ def __init__ (self , * args , ** kwargs ):
51+ super ().__init__ (* args , ** kwargs )
52+ self .attachments .supports_filtering = False
53+ self .attachments .supports_sorting = False
54+
55+ @property
56+ def metadata (self ) -> Dict [str , Union [str , List [Dict ]]]:
57+ """Get metadata for datarow
58+ """
59+
60+ query = """query GetDataRowMetadataBetaPyApi($dataRowID: ID!) {
61+ dataRow(where: {id: $dataRowID}) {
62+ customMetadata {
63+ value
64+ schemaId
65+ }
66+ }
67+ }
68+ """
69+
70+ metadata = self .client .execute (
71+ query , {"dataRowID" : self .uid })["dataRow" ]["customMetadata" ]
72+
73+ return {
74+ "data_row_id" :
75+ self .uid ,
76+ "fields" : [{
77+ "schema_id" : m ["schemaId" ],
78+ "value" : m ["value" ]
79+ } for m in metadata ]
80+ }
81+
5582 @staticmethod
5683 def bulk_delete (data_rows ):
5784 """ Deletes all the given DataRows.
@@ -61,13 +88,6 @@ def bulk_delete(data_rows):
6188 """
6289 BulkDeletable ._bulk_delete (data_rows , True )
6390
64- def __init__ (self , * args , ** kwargs ):
65- super ().__init__ (* args , ** kwargs )
66- self .metadata .supports_filtering = False
67- self .metadata .supports_sorting = False
68- self .attachments .supports_filtering = False
69- self .attachments .supports_sorting = False
70-
7191 def create_attachment (self , attachment_type , attachment_value ):
7292 """ Adds an AssetAttachment to a DataRow.
7393 Labelers can view these attachments while labeling.
@@ -108,21 +128,3 @@ def create_attachment(self, attachment_type, attachment_value):
108128 })
109129 return Entity .AssetAttachment (self .client ,
110130 res ["createDataRowAttachment" ])
111-
112- def create_metadata (self , meta_type , meta_value ):
113- """
114-
115- This function is deprecated. Use create_attachment instead
116-
117- Returns:
118- AssetMetadata
119- """
120- logger .warning (
121- "`create_metadata` is deprecated. Use `create_attachment` instead." )
122- attachment = self .create_attachment (meta_type , meta_value )
123- return Entity .AssetMetadata (
124- self .client , {
125- 'id' : attachment .uid ,
126- 'metaType' : attachment .attachment_type ,
127- 'metaValue' : attachment .attachment_value
128- })
0 commit comments