Skip to content
Snippets Groups Projects
Commit 82db1187 authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

Merge branch 'f-fix-multi-parent' into 'dev'

Multiple registered identifiables error when multiple parents exist

See merge request !218
parents 7a6252ad 3a5b3cf7
No related branches found
No related tags found
2 merge requests!222Release 0.12.0,!218Multiple registered identifiables error when multiple parents exist
Pipeline #62084 passed
......@@ -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 ###
......
......@@ -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:
......
......@@ -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")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment