Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/aind_data_schema/core/quality_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def fix_default_grouping_list(cls, value: dict) -> dict:
This function is for backwards compatibility with v2.2.X where default_grouping was stored as a list of strings.
Remove this function in aind-data-schema v3.X
"""
if "default_grouping" not in value:
if "default_grouping" not in value or "metrics" not in value or len(value["metrics"]) == 0:
return value

if all(isinstance(item, str) for item in value["default_grouping"]):
Expand Down
12 changes: 12 additions & 0 deletions tests/test_quality_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,18 @@ def test_new_format_default_grouping_mixed(self):
# Tags should remain as dict
self.assertEqual(qc_new.metrics[0].tags, {"group": "test_group", "probe": "probeA", "shank": "shank1"})

def test_empty_metrics_does_not_convert_default_grouping(self):
"""Test that fix_default_grouping_list does not alter default_grouping when metrics is empty"""

empty_metrics_dict = {
"metrics": [],
"default_grouping": ["group1", "group2"],
}

qc = QualityControl.model_validate(empty_metrics_dict)

self.assertEqual(qc.default_grouping, ["group1", "group2"])


if __name__ == "__main__":
unittest.main()
Loading