From cdb30ef2cf12b088e83fe4ad7771dcb41cb18d94 Mon Sep 17 00:00:00 2001 From: Reema Gupta Date: Thu, 8 Jan 2026 17:13:58 +0100 Subject: [PATCH 1/3] Fix TypeError in by_name() when name is not found When using `match="equals"` (the default), `by_name()` would return `None` from `dict.get(name, None)` if the name wasn't found in the lookup cache. This caused `len(matches)` on line 51 to raise: TypeError: object of type 'NoneType' has no len() This fix changes the default value from `None` to `[]` (empty list), making it consistent with the `match="contains"` branch which already initializes `matches = []`. --- pipeline/src/additional_methods/by_name.py.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipeline/src/additional_methods/by_name.py.txt b/pipeline/src/additional_methods/by_name.py.txt index 13491111..d363ab0a 100644 --- a/pipeline/src/additional_methods/by_name.py.txt +++ b/pipeline/src/additional_methods/by_name.py.txt @@ -38,7 +38,7 @@ else: cls._instance_lookup[key] = [instance] if match == "equals": - matches = cls._instance_lookup.get(name, None) + matches = cls._instance_lookup.get(name, []) elif match == "contains": matches = [] for key, instances in cls._instance_lookup.items(): From 4cb5a582d9cc0f39be8b2e2fdf728a7d5fd3ea1e Mon Sep 17 00:00:00 2001 From: Reema Gupta Date: Thu, 8 Jan 2026 17:47:52 +0100 Subject: [PATCH 2/3] fix: move empty result check up before checking if user asked for all --- pipeline/src/additional_methods/by_name.py.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pipeline/src/additional_methods/by_name.py.txt b/pipeline/src/additional_methods/by_name.py.txt index d363ab0a..1dcd7cd7 100644 --- a/pipeline/src/additional_methods/by_name.py.txt +++ b/pipeline/src/additional_methods/by_name.py.txt @@ -46,9 +46,9 @@ matches.extend(instances) else: raise ValueError("'match' must be either 'equals' or 'contains'") - if all: + if not matches: + return None + elif all: return matches - elif len(matches) > 0: - return matches[0] else: - return None + return matches[0] \ No newline at end of file From 044c23cc25f5552fe7655e090ef02473fcbc5ca9 Mon Sep 17 00:00:00 2001 From: Reema Gupta Date: Fri, 9 Jan 2026 10:52:29 +0100 Subject: [PATCH 3/3] add(test): tests for consistent None return for by_name method --- pipeline/tests/test_regressions.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pipeline/tests/test_regressions.py b/pipeline/tests/test_regressions.py index 359df163..962cba39 100644 --- a/pipeline/tests/test_regressions.py +++ b/pipeline/tests/test_regressions.py @@ -331,3 +331,17 @@ def test_issue0069(om): results = om.core.License.by_name("Creative Commons", all=True, match="contains") assert len(results) == 7 assert all("CC" in r.short_name for r in results) + +@pytest.mark.parametrize("om", [openminds.latest]) +def test_pr0083(om): + # https://github.com/openMetadataInitiative/openMINDS_Python/pull/83 + # by_name() should return None consistently + # when no matches are found, regardless of the 'all' parameter + + # all=False (default) should return None when no match is found + result = om.controlled_terms.BiologicalOrder.by_name("nonexistent_order_xyz") + assert result is None + + # all=True should also return None when no match is found + results = om.controlled_terms.BiologicalOrder.by_name("nonexistent_order_xyz", all=True) + assert results is None \ No newline at end of file