Recursion Error in __str__ implementation
Opened this issue · 2 comments
To reproduce, in importCIGREMV.py
, add:
o = import_result['topology']['_f71dc9cf-458e-4b79-9c3b-6e3a9b5cd398']
print(str(o))
Result: RecursionError: maximum recursion depth exceeded while getting the str of an object
Can also occur with Terminal
objects (where I first noticed it), ConformLoad
objects, SvPowerFlow
objects and possibly others.
This problem appears because of the existency of circular dependencies in CIM. For example, each topological node points to a SvVoltage object which points back to the topological node object. When we call the str funcion of the TopologicalNode class, it iterates through all its components and calls their respective str function (for example hier).
This means when we call the function str of the class Topological node, this calls the str function of the SvVoltage class, which calls the str function of TopologicalNode and the program ends in a infinite loop.
One possible solution is to use the repr method instead of the str method (see this branch)
@martinmoraga @dinkelbachjan Should we fix this in cimgen so that the error does not appear again after generating new code?