Skip to content
Snippets Groups Projects

Detect infinite recursion in Entity.to_xml

Merged I. Nüske requested to merge f-bug-fit-96-print-recursion into dev
All threads resolved!
Files
5
@@ -1232,7 +1232,7 @@ class Entity:
xml: Optional[etree._Element] = None,
add_properties: INHERITANCE = "ALL",
local_serialization: bool = False,
visited_entities: Optional[Union[list, None]] = None
visited_entities: Optional[list] = None
) -> etree._Element:
"""Generate an xml representation of this entity. If the parameter xml
is given, all attributes, parents, properties, and messages of this
@@ -1240,15 +1240,25 @@ class Entity:
Raise an error if xml is not a lxml.etree.Element
@param xml: an xml element to which all attributes, parents,
properties, and messages
are to be added.
@param visited_entities: recursion check, should never be set manually
FIXME: Add documentation for the add_properties parameter.
FIXME: Add documentation for the local_serialization parameter.
Parameters
----------
xml : etree._Element, optional
an xml element to which all attributes, parents,
properties, and messages are to be added. Default is None.
visited_entities : list, optional
list of enties that are being printed for recursion check,
should never be set manually. Default is None.
add_properties : INHERITANCE, optional
FIXME: Add documentation for the add_properties
parameter. Default is "ALL".
local_serialization : bool, optional
FIXME: Add documentation for the local_serialization
parameter. Default is False.
@return: xml representation of this entity.
Returns
-------
xml : etree._Element
xml representation of this entity.
"""
if xml is None:
@@ -1260,7 +1270,7 @@ class Entity:
if visited_entities is None:
visited_entities = []
if self in visited_entities:
xml.text = "..."
xml.text = xml2str(etree.Comment("Recursive reference"))
return xml
visited_entities.append(self)
@@ -1282,8 +1292,10 @@ class Entity:
xml.set("description", str(self.description))
if self.version is not None:
# Does version.to_xml need visited_entities support?
# It does have some recursion with predecessors / successors.
# If this ever causes problems, we might add
# visited_entities support here since it does have some
# recursion with predecessors / successors. But should be
# fine for now, since it is always set by the server.
xml.append(self.version.to_xml())
if self.value is not None:
Loading