Skip to content

Commit 19130e6

Browse files
committed
fix(core): map an unresolved iri to None instead of omitting it
oold types ResolveResult.nodes as Dict[str, Union[None, ...]] and indexes it by iri in three places without checking for the key, so omitting an unresolved iri turns a skipped page into a KeyError.
1 parent 6c6ee6d commit 19130e6

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

‎src/osw/core.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ def resolve(self, request: ResolveParam):
280280
entity = entities_by_title.get(iri)
281281
if entity is None:
282282
_logger.warning(f"Could not resolve iri '{iri}'")
283-
continue
283+
# ResolveResult.nodes is typed Dict[str, Union[None, ...]],
284+
# and oold indexes it by iri without checking for the key,
285+
# so an unresolved iri has to be present and None
284286
nodes[iri] = entity
285287
return ResolveResult(nodes=nodes)
286288

‎tests/test_load_entity_result_shape.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,12 @@ def _stub_load_entity(self, param):
8181
ResolveParam(iris=["Item:OSWAlignBad", "Item:OSWAlignGood"])
8282
)
8383

84-
assert result.nodes == {"Item:OSWAlignGood": good}
85-
assert "Item:OSWAlignBad" not in result.nodes
84+
# ResolveResult validates its values, which copies the entity, so compare
85+
# by equality rather than by identity
86+
assert result.nodes["Item:OSWAlignGood"] == good
87+
# oold indexes nodes by iri without checking for the key, and types the
88+
# values as Union[None, ...], so an unresolved iri maps to None
89+
assert result.nodes["Item:OSWAlignBad"] is None
8690

8791

8892
def test_resolve_returns_all_entities_when_every_iri_resolves(monkeypatch):

0 commit comments

Comments
 (0)