Skip to content

Commit e807e77

Browse files
committed
Add attachment_name support to create_attachment()
1 parent 2c688a7 commit e807e77

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

labelbox/schema/data_row.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,10 @@ def get_winning_label_id(self, project_id: str) -> Optional[str]:
106106

107107
return res["dataRow"]["labelingActivity"]["selectedLabelId"]
108108

109-
def create_attachment(self, attachment_type,
110-
attachment_value) -> "AssetAttachment":
109+
def create_attachment(self,
110+
attachment_type,
111+
attachment_value,
112+
attachment_name=None) -> "AssetAttachment":
111113
""" Adds an AssetAttachment to a DataRow.
112114
Labelers can view these attachments while labeling.
113115
@@ -117,6 +119,7 @@ def create_attachment(self, attachment_type,
117119
attachment_type (str): Asset attachment type, must be one of:
118120
VIDEO, IMAGE, TEXT, IMAGE_OVERLAY (AssetAttachment.AttachmentType)
119121
attachment_value (str): Asset attachment value.
122+
attachment_name (str): (Optional) Asset attachment name.
120123
Returns:
121124
`AssetAttachment` DB object.
122125
Raises:
@@ -126,19 +129,23 @@ def create_attachment(self, attachment_type,
126129

127130
attachment_type_param = "type"
128131
attachment_value_param = "value"
132+
attachment_name_param = "name"
129133
data_row_id_param = "dataRowId"
134+
130135
query_str = """mutation CreateDataRowAttachmentPyApi(
131-
$%s: AttachmentType!, $%s: String!, $%s: ID!) {
136+
$%s: AttachmentType!, $%s: String!, $%s: String, $%s: ID!) {
132137
createDataRowAttachment(data: {
133-
type: $%s value: $%s dataRowId: $%s}) {%s}} """ % (
134-
attachment_type_param, attachment_value_param, data_row_id_param,
135-
attachment_type_param, attachment_value_param, data_row_id_param,
138+
type: $%s value: $%s name: $%s dataRowId: $%s}) {%s}} """ % (
139+
attachment_type_param, attachment_value_param,
140+
attachment_name_param, data_row_id_param, attachment_type_param,
141+
attachment_value_param, attachment_name_param, data_row_id_param,
136142
query.results_query_part(Entity.AssetAttachment))
137143

138144
res = self.client.execute(
139145
query_str, {
140146
attachment_type_param: attachment_type,
141147
attachment_value_param: attachment_value,
148+
attachment_name_param: attachment_name,
142149
data_row_id_param: self.uid
143150
})
144151
return Entity.AssetAttachment(self.client,

tests/integration/test_data_rows.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,12 +685,24 @@ def test_create_data_rows_sync_mixed_upload(dataset, image_url):
685685

686686
def test_delete_data_row_attachment(datarow, image_url):
687687
attachments = []
688+
689+
# Anonymous attachment
688690
to_attach = [("IMAGE", image_url), ("TEXT", "test-text"),
689691
("IMAGE_OVERLAY", image_url), ("HTML", image_url)]
690692
for attachment_type, attachment_value in to_attach:
691693
attachments.append(
692694
datarow.create_attachment(attachment_type, attachment_value))
693695

696+
# Attachment with a name
697+
to_attach = [("IMAGE", image_url, "Att. Image"),
698+
("TEXT", "test-text", "Att. Text"),
699+
("IMAGE_OVERLAY", image_url, "Image Overlay"),
700+
("HTML", image_url, "Att. HTML")]
701+
for attachment_type, attachment_value, attachment_name in to_attach:
702+
attachments.append(
703+
datarow.create_attachment(attachment_type, attachment_value,
704+
attachment_name))
705+
694706
for attachment in attachments:
695707
attachment.delete()
696708

0 commit comments

Comments
 (0)