fix: resolve circular import in Component class (#8839)
* 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 <noreply@anthropic.com> * [autofix.ci] apply automated fixes --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
This commit is contained in:
parent
7ec3cb063d
commit
90d9ab2f64
1 changed files with 11 additions and 2 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue