Component
Python SDK
Task Description
RelatedNodeBase.__init__ (infrahub_sdk/node/related_node.py) needs to detect
whether the data it receives is a node instance. Because node.py imports
related_node.py at module load, related_node.py cannot import InfrahubNodeBase
at the top level — they form a circular dependency. The current check therefore
relies on a mid-function lazy import:
from .node import InfrahubNodeBase as _InfrahubNodeBase inside __init__.
This was introduced in #1090 to replace a too-broad hasattr(data, "_schema")
duck-typing check (which could accept non-node objects). The lazy import works and
is type-correct, but it's a workaround: the underlying problem is the circular
dependency between node.py and related_node.py and the absence of a clean
shared base / protocol that node-type detection can import without a cycle.
As @ajtmccarty noted on the PR, this is out of scope for #1090 but worth tracking.
The same duck-typing workaround likely appears elsewhere in the node layer, so a
structural fix (e.g. a dependency-free shared base or protocol module) would let
several call sites drop their lazy imports / hasattr checks.
References
Component
Python SDK
Task Description
RelatedNodeBase.__init__(infrahub_sdk/node/related_node.py) needs to detectwhether the
datait receives is a node instance. Becausenode.pyimportsrelated_node.pyat module load,related_node.pycannot importInfrahubNodeBaseat the top level — they form a circular dependency. The current check therefore
relies on a mid-function lazy import:
from .node import InfrahubNodeBase as _InfrahubNodeBaseinside__init__.This was introduced in #1090 to replace a too-broad
hasattr(data, "_schema")duck-typing check (which could accept non-node objects). The lazy import works and
is type-correct, but it's a workaround: the underlying problem is the circular
dependency between
node.pyandrelated_node.pyand the absence of a cleanshared base / protocol that node-type detection can import without a cycle.
As @ajtmccarty noted on the PR, this is out of scope for #1090 but worth tracking.
The same duck-typing workaround likely appears elsewhere in the node layer, so a
structural fix (e.g. a dependency-free shared base or protocol module) would let
several call sites drop their lazy imports /
hasattrchecks.References
infrahub_sdk/node/related_node.py:65)