Skip to content

Commit

Permalink
fix recursion issue (#563)
Browse files Browse the repository at this point in the history
  • Loading branch information
PythonFZ authored Apr 4, 2023
1 parent 53b918f commit f069ddb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/integration/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,9 @@ def test_project_remove_graph(proj_path):
assert node2.outputs == "Lorem Ipsum"
with pytest.raises(zntrack.exceptions.NodeNotAvailableError):
node.load()


def test_project_repr_node(tmp_path_2):
with zntrack.Project() as project:
node = WriteIO(inputs="Hello World")
print(node)
9 changes: 9 additions & 0 deletions zntrack/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ class Node(zninit.ZnInit, znflow.Node):

_protected_ = znflow.Node._protected_ + ["name"]

@property
def _use_repr_(self) -> bool:
"""Only use dataclass like __repr__ if outside the _graph_ to avoid recursion.
Due to modified behavior of '__getattribute__' inside the graph context,
a fallback to the python default '__repr__' is needed to avoid recursion.
"""
return self._graph_ is None

def _post_load_(self) -> None:
"""Post load hook.
Expand Down

0 comments on commit f069ddb

Please sign in to comment.