Skip to content

Commit f0a7398

Browse files
author
Val Brodsky
committed
Handle uuid for ndjson type
1 parent 41f0f59 commit f0a7398

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

libs/labelbox/src/labelbox/data/serialization/ndjson/base.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ def must_set_one(self):
2020

2121

2222
class NDJsonBase(_CamelCaseMixin):
23-
uuid: str = None
23+
uuid: str
2424
data_row: DataRow
2525

26-
@field_validator('uuid', mode='before')
26+
@model_validator(mode='before')
2727
@classmethod
28-
def set_id(cls, v):
29-
return v or str(uuid4())
28+
def set_uuid(cls, data):
29+
if data.get('uuid') is None:
30+
data['uuid'] = str(uuid4())
31+
return data
3032

3133
def dict(self, *args, **kwargs):
3234
""" Pop missing id or missing globalKey from dataRow """

libs/labelbox/src/labelbox/data/serialization/ndjson/converter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ def serialize(
113113
exclude={"uuid"} if annotation_uuid == "None" else None,
114114
exclude_none=True,
115115
)
116+
116117
for k, v in list(res.items()):
117118
if k in IGNORE_IF_NONE and v is None:
118119
del res[k]

libs/labelbox/tests/data/serialization/ndjson/test_video.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ def test_video():
2323
# assert res == [data[2], data[0], data[1], data[3], data[4], data[5]]
2424
assert (res[0]) == data[2]
2525
assert (res[1]) == data[0]
26-
answers = data[1].pop('answer')
27-
data[1]['answers'] = answers
2826
assert (res[2]) == data[1]
2927
assert (res[3]) == data[3]
3028
assert (res[4]) == data[4]

0 commit comments

Comments
 (0)