Unverified Commit 13913788 authored by Cyrus Leung's avatar Cyrus Leung Committed by GitHub
Browse files

[Bugfix] Fix edge case in UUID data parsing (#34884)


Signed-off-by: default avatarDarkLight1337 <tlleungac@connect.ust.hk>
parent f6220f98
...@@ -42,6 +42,16 @@ def test_multi_modal_uuids_length_mismatch_raises(): ...@@ -42,6 +42,16 @@ def test_multi_modal_uuids_length_mismatch_raises():
mm_data = {"image": [cherry_pil_image, stop_pil_image]} mm_data = {"image": [cherry_pil_image, stop_pil_image]}
# Mismatch: 2 items but only 0 uuids provided
mm_uuids = {"image": []} # type: ignore[var-annotated]
mm_processor = renderer.get_mm_processor()
mm_data_items = mm_processor.info.parse_mm_data(mm_data)
mm_uuid_items = parse_mm_uuids(mm_uuids)
with pytest.raises(ValueError, match="must have same length as"):
renderer._process_mm_uuids(mm_data, mm_data_items, mm_uuid_items, "req-1a")
# Mismatch: 2 items but only 1 uuid provided # Mismatch: 2 items but only 1 uuid provided
mm_uuids = {"image": ["hash_cherry"]} mm_uuids = {"image": ["hash_cherry"]}
...@@ -50,7 +60,7 @@ def test_multi_modal_uuids_length_mismatch_raises(): ...@@ -50,7 +60,7 @@ def test_multi_modal_uuids_length_mismatch_raises():
mm_uuid_items = parse_mm_uuids(mm_uuids) mm_uuid_items = parse_mm_uuids(mm_uuids)
with pytest.raises(ValueError, match="must have same length as"): with pytest.raises(ValueError, match="must have same length as"):
renderer._process_mm_uuids(mm_data, mm_data_items, mm_uuid_items, "req-1") renderer._process_mm_uuids(mm_data, mm_data_items, mm_uuid_items, "req-1b")
def test_multi_modal_uuids_missing_modality_raises(): def test_multi_modal_uuids_missing_modality_raises():
...@@ -125,8 +135,8 @@ def test_multi_modal_uuids_accepts_empty( ...@@ -125,8 +135,8 @@ def test_multi_modal_uuids_accepts_empty(
# While None means cached multi-modal input requiring UUIDs # While None means cached multi-modal input requiring UUIDs
# an empty list means no multi-modal input # an empty list means no multi-modal input
mm_data = {"image": [], "video": []} # type: ignore[var-annotated] mm_data = {"image": [], "video": [], "audio": None} # type: ignore[var-annotated]
mm_uuids = {"image": [], "video": None} # type: ignore[var-annotated] mm_uuids = {"image": [], "video": None, "audio": []} # type: ignore[var-annotated]
mm_processor = renderer.get_mm_processor() mm_processor = renderer.get_mm_processor()
mm_data_items = mm_processor.info.parse_mm_data(mm_data) mm_data_items = mm_processor.info.parse_mm_data(mm_data)
......
...@@ -482,7 +482,7 @@ class BaseRenderer(ABC, Generic[_T]): ...@@ -482,7 +482,7 @@ class BaseRenderer(ABC, Generic[_T]):
) )
elif uuid_items is not None: elif uuid_items is not None:
if len(uuid_items) > 0 and len(data_items) != len(uuid_items): if len(data_items) != len(uuid_items):
raise ValueError( raise ValueError(
f"If given, multi_modal_uuids[{modality!r}] must have " f"If given, multi_modal_uuids[{modality!r}] must have "
f"same length as multi_modal_data[{modality!r}], but " f"same length as multi_modal_data[{modality!r}], but "
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment