From fae7f98d4daa91d10add80dad2fb2555bb5c5666 Mon Sep 17 00:00:00 2001 From: Andrew Davison Date: Thu, 31 Jul 2025 23:49:15 +0200 Subject: [PATCH 1/2] Add test, which currently fails, demonstrating the bug --- pipeline/tests/test_regressions.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pipeline/tests/test_regressions.py b/pipeline/tests/test_regressions.py index 2c750a94..595b70b2 100644 --- a/pipeline/tests/test_regressions.py +++ b/pipeline/tests/test_regressions.py @@ -235,3 +235,22 @@ def test_issue0023(): assert len(dv_again.custodians[0].affiliations) == 2 assert dv_again.custodians[0].affiliations[0].member_of.full_name == "University of This Place" assert dv_again.custodians[0].affiliations[1].member_of.full_name == "University of That Place" + + +def test_issue0056(): + # https://github.com/openMetadataInitiative/openMINDS_Python/issues/56 + # Since we are permissive on object creation, serialization to JSON-LD should work + # even if the object gives validation failures. + # However, under some circumstances, to_jsonld() produces a data structure + # that cannot be saved as a JSON string. + dataset = omcore.Dataset( + digital_identifier=[ + omcore.DOI(identifier="abc"), + omcore.DOI(identifier="def") + ] + ) + failures = dataset.validate(ignore=["required"]) + assert len(failures) == 1 + assert failures["multiplicity"] == ['digital_identifier does not accept multiple values, but contains 2'] + data = dataset.to_jsonld() + json.dumps(data) # this should not raise an Exception From d1ffe0e54dadc800b06321f37507e09b29f52b9f Mon Sep 17 00:00:00 2001 From: Andrew Davison Date: Wed, 30 Jul 2025 15:07:44 +0200 Subject: [PATCH 2/2] Failure to validate should not necessarily mean failure to export as JSON-LD --- pipeline/src/base.py | 11 +++++++++++ pipeline/src/properties.py | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pipeline/src/base.py b/pipeline/src/base.py index 47d4d703..5bb2f275 100644 --- a/pipeline/src/base.py +++ b/pipeline/src/base.py @@ -92,6 +92,17 @@ def to_jsonld(self, include_empty_properties=True, embed_linked_nodes=True, with ) for item in value ] + elif isinstance(value, (tuple, list)): + # if property.multiple is False, then this means the node does not validate, + # but we should try to serialize it anyway + data[property.path] = [ + value_to_jsonld( + item, + include_empty_properties=include_empty_properties, + embed_linked_nodes=embed_linked_nodes, + ) + for item in value + ] else: data[property.path] = value_to_jsonld( value, diff --git a/pipeline/src/properties.py b/pipeline/src/properties.py index ba432353..ad730392 100644 --- a/pipeline/src/properties.py +++ b/pipeline/src/properties.py @@ -194,7 +194,7 @@ def deserialize_item(item): else: raise NotImplementedError() - if self.multiple and isinstance(data, (tuple, list)): + if isinstance(data, (tuple, list)): return [deserialize_item(item) for item in data] else: return deserialize_item(data)