diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e88f71b2577177de5ce658b2ec83f86db6d065c..33fdff70f9af8d1c2174dc0ec297b08762fdeb63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed ### ### Fixed ### +- A RecordType with multiple Parents no longer causes an error during + collection of identifiables ### Security ### diff --git a/src/caoscrawler/identifiable_adapters.py b/src/caoscrawler/identifiable_adapters.py index 6169a99e7bf47daffb53332b7e0b6513730f2561..444b73f5d9a42cf8ec23eec7cb718b1fc183dd30 100644 --- a/src/caoscrawler/identifiable_adapters.py +++ b/src/caoscrawler/identifiable_adapters.py @@ -672,11 +672,15 @@ class CaosDBIdentifiableAdapter(IdentifiableAdapter): registered = [] for parent in rt.parents: prt = _retrieve_RecordType(id=parent.id, name=parent.name) - registered.append(self._get_registered_for_rt(prt)) + reg = self._get_registered_for_rt(prt) + if reg is not None: + registered.append(reg) # TODO we might in future want to check whether the registered identifiables are the same if len(registered) > 1: - raise RuntimeError("Multiple registered identifiables found for the RecordType " - f" {rt.name} with the following parents: {rt.parents}") + ri_names = [i.name for i in registered] + raise RuntimeError(f"Multiple registered identifiables found for the RecordType " + f" {rt.name} with the following parents: {rt.parents}\n" + f"Registered identifiables: {', '.join(ri_names)}") elif len(registered) == 1: return registered[0] else: diff --git a/unittests/test_identifiable_adapters.py b/unittests/test_identifiable_adapters.py index 5108e83c83db16f1b44d836bf22d21d8e871ee8f..1c7733acfe952a2f47eff2853c2b90684c098dbf 100644 --- a/unittests/test_identifiable_adapters.py +++ b/unittests/test_identifiable_adapters.py @@ -54,7 +54,9 @@ def mock_retrieve_RecordType(id, name): "Lab": db.RecordType(name="Lab"), "Analysis": db.RecordType(name="Analysis"), "MetaAnalysis": db.RecordType(name="MetaAnalysis").add_parent("Analysis"), - "Measurement": db.RecordType(name="Measurement").add_parent("Experiment") + # Test that two parents are possible; only one of them + # (Experiment) has an identifiable. + "Measurement": db.RecordType(name="Measurement").add_parent("Experiment").add_parent("A") }[name] @@ -330,8 +332,10 @@ def test_get_registered_identifiable(): with pytest.raises(RuntimeError): registered = ident.get_registered_identifiable(rec) - # Test the case that the record has a parent for which no identifiable is registered - # and there is a registered identifiable for a grand parent + # Test the case that the record has a parent for which no + # identifiable is registered and there is a registered + # identifiable for a grand parent. Note that this also tests the + # case of two grandparents, only one of which has an identifiable. ident = CaosDBIdentifiableAdapter() ident.load_from_yaml_definition(UNITTESTDIR / "example_identifiables.yml") rec = db.Record().add_parent(name="Measurement")