Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ def serialize(
"""

for label in labels:
if hasattr(label, "data") and label.data is not None:
uid = getattr(label.data, "uid", None)
global_key = getattr(label.data, "global_key", None)
if uid is None and global_key is None:
raise ValueError(
"NDJSON serialization/import does not support referencing data rows by external_id. "
"Please use global_key or resolve external_id to a data_row_id."
)
for example in NDLabel.from_common([label]):
annotation_uuid = getattr(example, "uuid", None)
res = example.model_dump(
Expand Down
29 changes: 29 additions & 0 deletions libs/labelbox/tests/unit/test_mal_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,32 @@ def test_invalid_labels_format():
MALPredictionImport.create_from_objects(
client=MagicMock(), project_id=id, name=id, predictions=label
)


def test_external_id_import_raises_value_error():
import labelbox.data.annotation_types as lb_types
from labelbox import MALPredictionImport

id = str(uuid.uuid4())
bbox_annotation = lb_types.ObjectAnnotation(
name="something",
value=lb_types.Rectangle(
start=lb_types.Point(x=100, y=100),
end=lb_types.Point(x=200, y=200)
)
)
labels = [
lb_types.Label(
data={"external_id": "name.jpg"},
annotations=[bbox_annotation]
)
]
with pytest.raises(ValueError) as excinfo:
MALPredictionImport.create_from_objects(
client=MagicMock(),
project_id=id,
name=id,
predictions=labels
)
assert "NDJSON serialization/import does not support referencing data rows by external_id" in str(excinfo.value)

Loading