Skip to content

Commit 6804637

Browse files
authored
Merge pull request #485 from Labelbox/AL-1716
[AL-1716] Datarow Delete Attachment
2 parents 6512fdd + c766e30 commit 6804637

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

labelbox/schema/asset_attachment.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,11 @@ def validate_attachment_type(cls, attachment_type: str) -> None:
4242
raise ValueError(
4343
f"meta_type must be one of {valid_types}. Found {attachment_type}"
4444
)
45+
46+
def delete(self) -> None:
47+
"""Deletes an attachment on the data row."""
48+
query_str = """mutation deleteDataRowAttachmentPyApi($attachment_id: ID!) {
49+
deleteDataRowAttachment(where: {id: $attachment_id}) {
50+
id}
51+
}"""
52+
self.client.execute(query_str, {"attachment_id": self.uid})

labelbox/schema/data_row.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,4 @@ def create_attachment(self, attachment_type,
9595
data_row_id_param: self.uid
9696
})
9797
return Entity.AssetAttachment(self.client,
98-
res["createDataRowAttachment"])
98+
res["createDataRowAttachment"])

tests/integration/test_data_rows.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import requests
77

88
from labelbox import DataRow
9-
from labelbox.exceptions import InvalidQueryError
109

1110

1211
def test_get_data_row(datarow, client):
@@ -276,3 +275,17 @@ def test_create_data_rows_sync_mixed_upload(dataset, image_url):
276275
DataRow.row_data: image_url
277276
}] * n_urls + [fp.name] * n_local)
278277
assert len(list(dataset.data_rows())) == n_local + n_urls
278+
279+
280+
def test_delete_data_row_attachment(datarow, image_url):
281+
attachments = []
282+
to_attach = [("IMAGE", image_url), ("TEXT", "test-text"),
283+
("IMAGE_OVERLAY", image_url), ("HTML", image_url)]
284+
for attachment_type, attachment_value in to_attach:
285+
attachments.append(
286+
datarow.create_attachment(attachment_type, attachment_value))
287+
288+
for attachment in attachments:
289+
attachment.delete()
290+
291+
assert len(list(datarow.attachments())) == 0

0 commit comments

Comments
 (0)