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

FIX: added further recursion detections

parent 666d6d41
Branches
Tags
1 merge request!109Detection of cyclic references for high level API
Pipeline #38495 passed with warnings
...@@ -265,7 +265,8 @@ class CaosDBPythonEntity(object): ...@@ -265,7 +265,8 @@ class CaosDBPythonEntity(object):
self._version = val self._version = val
def _set_property_from_entity(self, ent: db.Entity, importance: str, def _set_property_from_entity(self, ent: db.Entity, importance: str,
references: Optional[db.Container]): references: Optional[db.Container],
visited: Dict[int, "CaosDBPythonEntity"]):
""" """
Set a new property using an entity from the normal python API. Set a new property using an entity from the normal python API.
...@@ -280,7 +281,7 @@ class CaosDBPythonEntity(object): ...@@ -280,7 +281,7 @@ class CaosDBPythonEntity(object):
raise RuntimeError("Multiproperty not implemented yet.") raise RuntimeError("Multiproperty not implemented yet.")
val = self._type_converted_value(ent.value, ent.datatype, val = self._type_converted_value(ent.value, ent.datatype,
references) references, visited)
self.set_property( self.set_property(
ent.name, ent.name,
val, val,
...@@ -382,7 +383,8 @@ class CaosDBPythonEntity(object): ...@@ -382,7 +383,8 @@ class CaosDBPythonEntity(object):
def _type_converted_list(self, def _type_converted_list(self,
val: List, val: List,
pr: str, pr: str,
references: Optional[db.Container]): references: Optional[db.Container],
visited: Dict[int, "CaosDBPythonEntity"]):
""" """
Convert a list to a python list of the correct type. Convert a list to a python list of the correct type.
...@@ -396,13 +398,14 @@ class CaosDBPythonEntity(object): ...@@ -396,13 +398,14 @@ class CaosDBPythonEntity(object):
raise RuntimeError("Not a list.") raise RuntimeError("Not a list.")
return [ return [
self._type_converted_value(i, get_list_datatype(pr), references self._type_converted_value(i, get_list_datatype(pr), references,
) for i in val] visited) for i in val]
def _type_converted_value(self, def _type_converted_value(self,
val: Any, val: Any,
pr: str, pr: str,
references: Optional[db.Container]): references: Optional[db.Container],
visited: Dict[int, "CaosDBPythonEntity"]):
""" """
Convert val to the correct type which is indicated by the database Convert val to the correct type which is indicated by the database
type string in pr. type string in pr.
...@@ -416,9 +419,9 @@ class CaosDBPythonEntity(object): ...@@ -416,9 +419,9 @@ class CaosDBPythonEntity(object):
# this needs to be checked as second case as it is the ONLY # this needs to be checked as second case as it is the ONLY
# case which does not depend on pr # case which does not depend on pr
# TODO: we might need to pass through the reference container # TODO: we might need to pass through the reference container
return convert_to_python_object(val, references) return convert_to_python_object(val, references, visited)
elif isinstance(val, list): elif isinstance(val, list):
return self._type_converted_list(val, pr, references) return self._type_converted_list(val, pr, references, visited)
elif pr is None: elif pr is None:
return val return val
elif pr == DOUBLE: elif pr == DOUBLE:
...@@ -436,7 +439,7 @@ class CaosDBPythonEntity(object): ...@@ -436,7 +439,7 @@ class CaosDBPythonEntity(object):
elif pr == DATETIME: elif pr == DATETIME:
return self._parse_datetime(val) return self._parse_datetime(val)
elif is_list_datatype(pr): elif is_list_datatype(pr):
return self._type_converted_list(val, pr, references) return self._type_converted_list(val, pr, references, visited)
else: else:
# Generic references to entities: # Generic references to entities:
return CaosDBPythonUnresolvedReference(val) return CaosDBPythonUnresolvedReference(val)
...@@ -843,7 +846,8 @@ def _single_convert_to_python_object(robj: CaosDBPythonEntity, ...@@ -843,7 +846,8 @@ def _single_convert_to_python_object(robj: CaosDBPythonEntity,
robj.__setattr__(base_attribute, val) robj.__setattr__(base_attribute, val)
for prop in entity.properties: for prop in entity.properties:
robj._set_property_from_entity(prop, entity.get_importance(prop), references) robj._set_property_from_entity(prop, entity.get_importance(prop), references,
visited)
for parent in entity.parents: for parent in entity.parents:
robj.add_parent(CaosDBPythonUnresolvedParent(id=parent.id, robj.add_parent(CaosDBPythonUnresolvedParent(id=parent.id,
...@@ -955,7 +959,10 @@ def convert_to_python_object(entity: Union[db.Container, db.Entity], ...@@ -955,7 +959,10 @@ def convert_to_python_object(entity: Union[db.Container, db.Entity],
# TODO: recursion problems? # TODO: recursion problems?
return _single_convert_to_python_object( return _single_convert_to_python_object(
high_level_type_for_standard_type(entity)(), entity, references, visited) high_level_type_for_standard_type(entity)(),
entity,
references,
visited)
def new_high_level_entity(entity: db.RecordType, def new_high_level_entity(entity: db.RecordType,
...@@ -993,7 +1000,7 @@ def new_high_level_entity(entity: db.RecordType, ...@@ -993,7 +1000,7 @@ def new_high_level_entity(entity: db.RecordType,
return convert_to_python_object(r) return convert_to_python_object(r)
def create_record(rtname: str, name: str = None, **kwargs): def create_record(rtname: str, name: Optional[str] = None, **kwargs):
""" """
Create a new record based on the name of a record type. The new record is returned. Create a new record based on the name of a record type. The new record is returned.
...@@ -1032,7 +1039,9 @@ def create_entity_container(record: CaosDBPythonEntity): ...@@ -1032,7 +1039,9 @@ def create_entity_container(record: CaosDBPythonEntity):
return db.Container().extend(lse) return db.Container().extend(lse)
def query(query: str, resolve_references: bool = True, references: db.Container = None): def query(query: str,
resolve_references: Optional[bool] = True,
references: Optional[db.Container] = None):
""" """
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment