11from labelbox .orm import query
22from labelbox .orm .db_object import DbObject , Updateable , BulkDeletable
33from labelbox .orm .model import Entity , Field , Relationship
4- from labelbox .schema .asset_metadata import AssetMetadata
4+ from labelbox .schema .asset_attchment import AssetAttachment
55
6+ import logging
7+
8+ logger = logging .getLogger (__name__ )
69
710class DataRow (DbObject , Updateable , BulkDeletable ):
811 """ Internal Labelbox representation of a single piece of data (e.g. image, video, text).
@@ -33,12 +36,15 @@ class DataRow(DbObject, Updateable, BulkDeletable):
3336 created_by = Relationship .ToOne ("User" , False , "created_by" )
3437 organization = Relationship .ToOne ("Organization" , False )
3538 labels = Relationship .ToMany ("Label" , True )
39+
3640 metadata = Relationship .ToMany ("AssetMetadata" , False , "metadata" )
41+ # attachments
42+ attachment = Relationship .ToMany ("AssetAttachment" , False , "attachment" )
3743
3844 predictions = Relationship .ToMany ("Prediction" , False )
3945
40- supported_meta_types = {
41- meta_type .value for meta_type in AssetMetadata .MetaType
46+ supported_meta_types = supported_attachment_types = {
47+ attachment_type .value for attachment_type in AssetAttachment .MetaType
4248 }
4349
4450 @staticmethod
@@ -54,42 +60,66 @@ def __init__(self, *args, **kwargs):
5460 super ().__init__ (* args , ** kwargs )
5561 self .metadata .supports_filtering = False
5662 self .metadata .supports_sorting = False
63+ self .attachment .supports_filtering = False
64+ self .attachment .supports_sorting = False
5765
58- def create_metadata (self , meta_type , meta_value ):
66+ def create_attachment (self , attachment_type , attachment_value ):
5967 """ Attaches asset metadata to a DataRow.
6068
61- >>> datarow.create_metadata ("TEXT", "This is a text message")
69+ >>> datarow.create_attachment ("TEXT", "This is a text message")
6270
6371 Args:
64- meta_type (str): Asset metadata type, must be one of:
65- VIDEO, IMAGE, TEXT, IMAGE_OVERLAY (AssetMetadata.MetaType )
66- meta_value (str): Asset metadata value.
72+ meta_type (str): Asset attachment type, must be one of:
73+ VIDEO, IMAGE, TEXT, IMAGE_OVERLAY (AssetAttachment.AttachmentType )
74+ meta_value (str): Asset attachment value.
6775 Returns:
68- `AssetMetadata ` DB object.
76+ `AssetAttachment ` DB object.
6977 Raises:
70- ValueError: meta_type must be one of the supported types.
78+ ValueError: asset_type must be one of the supported types.
7179 """
7280
73- if meta_type not in self .supported_meta_types :
81+ if attachment_type not in self .supported_attachment_types :
7482 raise ValueError (
75- f"meta_type must be one of { self .supported_meta_types } . Found { meta_type } "
83+ f"meta_type must be one of { self .supported_attachment_types } . Found { attachment_type } "
7684 )
7785
78- meta_type_param = "metaType "
79- meta_value_param = "metaValue "
86+ attachment_type_param = "type "
87+ attachment_value_param = "value "
8088 data_row_id_param = "dataRowId"
81- query_str = """mutation CreateAssetMetadataPyApi (
89+ query_str = """mutation CreateDataRowAttachmentPyApi (
8290 $%s: AttachmentType!, $%s: String!, $%s: ID!) {
83- createAssetMetadata (data: {
84- metaType : $%s metaValue : $%s dataRowId: $%s}) {%s}} """ % (
85- meta_type_param , meta_value_param , data_row_id_param ,
86- meta_type_param , meta_value_param , data_row_id_param ,
91+ createDataRowAttachment (data: {
92+ type : $%s value : $%s dataRowId: $%s}) {%s}} """ % (
93+ attachment_type_param , attachment_value_param , data_row_id_param ,
94+ attachment_type_param , attachment_value_param , data_row_id_param ,
8795 query .results_query_part (Entity .AssetMetadata ))
8896
8997 res = self .client .execute (
9098 query_str , {
91- meta_type_param : meta_type ,
92- meta_value_param : meta_value ,
99+ attachment_type_param : meta_type ,
100+ attachment_value_param : meta_value ,
93101 data_row_id_param : self .uid
94102 })
103+ return Entity .AssetAttachment (self .client , res ["createAssetMetadata" ])
104+
105+
106+ createDataRowAttachment (data : DataRowAttachmentCreateInput !): DataRowAttachment !
107+ deleteDataRowAttachment (where : WhereUniqueIdInput !): DataRowAttachment !
108+ updateDataRowAttachment
109+
110+
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+ )
123+
124+ attachment = self .create_attachment (meta_type , meta_value )
95125 return Entity .AssetMetadata (self .client , res ["createAssetMetadata" ])
0 commit comments