From 90d9ab2f64dc72562032f0c7cea52c9efa54a424 Mon Sep 17 00:00:00 2001 From: Rodrigo Nader Date: Mon, 7 Jul 2025 13:01:28 -0300 Subject: [PATCH] fix: resolve circular import in Component class (#8839) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: resolve circular import in Component class Move graph-related imports inside methods to break circular dependency chain: - Move create_state_model import inside _build_state_model method - Move has_chat_output import inside is_connected_to_chat_output method This enables component testing without circular import errors that were preventing execution of component test suites. Fixes circular import chain: Component -> graph.state.model -> graph.vertex -> Component 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * [autofix.ci] apply automated fixes --------- Co-authored-by: Claude Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Gabriel Luiz Freitas Almeida --- .../langflow/custom/custom_component/component.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/backend/base/langflow/custom/custom_component/component.py b/src/backend/base/langflow/custom/custom_component/component.py index 85f2810d1..622b61b31 100644 --- a/src/backend/base/langflow/custom/custom_component/component.py +++ b/src/backend/base/langflow/custom/custom_component/component.py @@ -24,8 +24,11 @@ from langflow.base.tools.constants import ( from langflow.custom.tree_visitor import RequiredInputsVisitor from langflow.exceptions.component import StreamingError from langflow.field_typing import Tool # noqa: TC001 Needed by _add_toolkit_output -from langflow.graph.state.model import create_state_model -from langflow.graph.utils import has_chat_output + +# Lazy import to avoid circular dependency +# from langflow.graph.state.model import create_state_model +# Lazy import to avoid circular dependency +# from langflow.graph.utils import has_chat_output from langflow.helpers.custom import format_type from langflow.memory import astore_message, aupdate_messages, delete_message from langflow.schema.artifact import get_artifact_type, post_process_raw @@ -298,6 +301,9 @@ class Component(CustomComponent): fields = {} for output in self._outputs_map.values(): fields[output.name] = getattr(self, output.method) + # Lazy import to avoid circular dependency + from langflow.graph.state.model import create_state_model + self._state_model = create_state_model(model_name=model_name, **fields) return self._state_model @@ -1447,6 +1453,9 @@ class Component(CustomComponent): ) def is_connected_to_chat_output(self) -> bool: + # Lazy import to avoid circular dependency + from langflow.graph.utils import has_chat_output + return has_chat_output(self.graph.get_vertex_neighbors(self._vertex)) def _should_skip_message(self, message: Message) -> bool: