Skip to content
Snippets Groups Projects
Commit bd7f3ed7 authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

ENH: default role is Record in high level API and implemented generic list support

parent 5d508313
No related branches found
No related tags found
2 merge requests!57RELEASE 0.7.3,!52F refactor high level api
Pipeline #20082 failed
...@@ -606,7 +606,10 @@ class CaosDBPythonEntity(object): ...@@ -606,7 +606,10 @@ class CaosDBPythonEntity(object):
Deserialize a yaml representation of an entity in high level API form. Deserialize a yaml representation of an entity in high level API form.
""" """
entity = high_level_type_for_role(serialization["role"])() if "role" in serialization:
entity = high_level_type_for_role(serialization["role"])()
else:
entity = CaosDBPythonRecord()
for parent in serialization["parents"]: for parent in serialization["parents"]:
if "unresolved" in parent: if "unresolved" in parent:
...@@ -795,6 +798,18 @@ def _single_convert_to_python_object(robj: CaosDBPythonEntity, ...@@ -795,6 +798,18 @@ def _single_convert_to_python_object(robj: CaosDBPythonEntity,
return robj return robj
def _convert_property_value(propval):
if isinstance(propval, CaosDBPythonUnresolvedReference):
propval = propval.id
elif isinstance(propval, CaosDBPythonEntity):
propval = _single_convert_to_entity(
standard_type_for_high_level_type(propval)(), propval)
elif isinstance(propval, list):
propval = [_convert_property_value(element) for element in propval]
# TODO: test case for list missing
return propval
def _single_convert_to_entity(entity: db.Entity, def _single_convert_to_entity(entity: db.Entity,
robj: CaosDBPythonEntity): robj: CaosDBPythonEntity):
...@@ -833,15 +848,7 @@ def _single_convert_to_entity(entity: db.Entity, ...@@ -833,15 +848,7 @@ def _single_convert_to_entity(entity: db.Entity,
propval = robj.__getattribute__(prop) propval = robj.__getattribute__(prop)
metadata = robj.get_property_metadata(prop) metadata = robj.get_property_metadata(prop)
if isinstance(propval, CaosDBPythonUnresolvedReference): propval = _convert_property_value(propval)
propval = propval.id
elif isinstance(propval, CaosDBPythonEntity):
propval = _single_convert_to_entity(
standard_type_for_high_level_type(propval)(), propval)
elif isinstance(propval, list):
# propval = []
if not isinstance(propval[0], int):
raise NotImplementedError()
entity.add_property( entity.add_property(
name=prop, name=prop,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment