Skip to content

Commit 0a1e147

Browse files
author
Kevin Kim
committed
Another commit
1 parent 15fe307 commit 0a1e147

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

labelbox/schema/data_row_metadata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def _batch_upsert(
295295
data_row_id=m.data_row_id,
296296
fields=list(
297297
chain.from_iterable(
298-
self._parse_upsert(m) for m in m.fields))).dict(
298+
self.parse_upsert(m) for m in m.fields))).dict(
299299
by_alias=True))
300300

301301
res = _batch_operations(_batch_upsert, items, self._batch_size)
@@ -393,7 +393,7 @@ def _bulk_export(_data_row_ids: List[str]) -> List[DataRowMetadata]:
393393
data_row_ids,
394394
batch_size=self._batch_size)
395395

396-
def _parse_upsert(
396+
def parse_upsert(
397397
self, metadatum: DataRowMetadataField
398398
) -> List[_UpsertDataRowMetadataInput]:
399399
"""Format for metadata upserts to GQL"""

labelbox/schema/dataset.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from collections.abc import Iterable
66
import time
77
import ndjson
8-
from itertools import islice
8+
from itertools import islice, chain
99

1010
from concurrent.futures import ThreadPoolExecutor, as_completed
1111
from io import StringIO
@@ -256,6 +256,18 @@ def validate_attachments(item):
256256
)
257257
return attachments
258258

259+
def parse_metadata_fields(item):
260+
metadata_fields = item.get('metadata_fields')
261+
if metadata_fields:
262+
mdo = self.client.get_data_row_metadata_ontology()
263+
metadata = list(
264+
chain.from_iterable(
265+
mdo.parse_upsert(m) for m in metadata_fields))
266+
metadata_fields = [
267+
md.dict(by_alias=True) for md in metadata
268+
]
269+
item['metadata_fields'] = metadata_fields
270+
259271
def format_row(item):
260272
# Formats user input into a consistent dict structure
261273
if isinstance(item, dict):
@@ -289,13 +301,16 @@ def convert_item(item):
289301
# Don't make any changes to tms data
290302
if "tileLayerUrl" in item:
291303
validate_attachments(item)
292-
return item
304+
return item
293305
# Convert all payload variations into the same dict format
294306
item = format_row(item)
295307
# Make sure required keys exist (and there are no extra keys)
296308
validate_keys(item)
297309
# Make sure attachments are valid
298310
validate_attachments(item)
311+
print(f"!! Before parsing metadata field: {item}")
312+
parse_metadata_fields(item)
313+
print(f"!! After parsing metadata field: {item}")
299314
# Upload any local file paths
300315
item = upload_if_necessary(item)
301316

0 commit comments

Comments
 (0)