Skip to content

Commit 587d3e3

Browse files
authored
Fix Scene metadata update workflow: get scene followed by re-upload should be seamless (#179)
* fix get and serialize scene * add test coverage
1 parent 64c7bd8 commit 587d3e3

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

nucleus/dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ def get_scene(self, reference_id: str) -> Scene:
10321032
:class:`Scene<LidarScene>`: A scene object containing frames, which
10331033
in turn contain pointcloud or image items.
10341034
"""
1035-
return Scene.from_json(
1035+
return LidarScene.from_json(
10361036
self._client.make_request(
10371037
payload=None,
10381038
route=f"dataset/{self.id}/scene/{reference_id}",

nucleus/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ def serialize_and_write(
218218
upload_units: Sequence[Union[DatasetItem, Annotation, LidarScene]],
219219
file_pointer,
220220
):
221+
if len(upload_units) == 0:
222+
raise ValueError(
223+
"Expecting at least one object when serializing objects to upload, but got zero. Please try again."
224+
)
221225
for unit in upload_units:
222226
try:
223227
if isinstance(unit, (DatasetItem, Annotation, LidarScene)):

tests/test_scene.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,65 @@ def test_scene_upload_async(dataset_scene):
341341
}
342342

343343

344+
@pytest.mark.integration
345+
def test_scene_upload_and_update(dataset_scene):
346+
payload = TEST_LIDAR_SCENES
347+
scenes = [
348+
LidarScene.from_json(scene_json) for scene_json in payload[SCENES_KEY]
349+
]
350+
reference_ids = [s.reference_id for s in scenes]
351+
update = payload[UPDATE_KEY]
352+
353+
job = dataset_scene.append(scenes, update=update, asynchronous=True)
354+
job.sleep_until_complete()
355+
status = job.status()
356+
357+
assert status == {
358+
"job_id": job.job_id,
359+
"status": "Completed",
360+
"message": {
361+
"scene_upload_progress": {
362+
"errors": [],
363+
"dataset_id": dataset_scene.id,
364+
"new_scenes": len(scenes),
365+
"ignored_scenes": 0,
366+
"scenes_errored": 0,
367+
"updated_scenes": 0,
368+
}
369+
},
370+
"job_progress": "1.00",
371+
"completed_steps": 1,
372+
"total_steps": 1,
373+
}
374+
375+
fetched_scenes = [
376+
dataset_scene.get_scene(ref_id) for ref_id in reference_ids
377+
]
378+
assert len(fetched_scenes) == len(scenes)
379+
380+
job2 = dataset_scene.append(scenes, update=True, asynchronous=True)
381+
job2.sleep_until_complete()
382+
status2 = job2.status()
383+
384+
assert status2 == {
385+
"job_id": job2.job_id,
386+
"status": "Completed",
387+
"message": {
388+
"scene_upload_progress": {
389+
"errors": [],
390+
"dataset_id": dataset_scene.id,
391+
"new_scenes": 0,
392+
"ignored_scenes": 0,
393+
"scenes_errored": 0,
394+
"updated_scenes": len(scenes),
395+
}
396+
},
397+
"job_progress": "1.00",
398+
"completed_steps": 1,
399+
"total_steps": 1,
400+
}
401+
402+
344403
@pytest.mark.integration
345404
def test_scene_upload_async_item_dataset(dataset_item):
346405
payload = TEST_LIDAR_SCENES

0 commit comments

Comments
 (0)