fixed! :)

This commit is contained in:
Reinier van der Leer
2026-02-12 10:07:43 +01:00
parent 85d97a9d5c
commit 6591b2171c
5 changed files with 18 additions and 37 deletions

View File

@@ -1,13 +1 @@
def _rebuild_library_agent_preset() -> None:
"""Deferred model rebuild to avoid circular import."""
from backend.api.features.library.model import LibraryAgentPreset
from .graph import NodeModel
from .integrations import Webhook # noqa: F401
# Resolve Webhook forward references
NodeModel.model_rebuild()
LibraryAgentPreset.model_rebuild()
_rebuild_library_agent_preset()

View File

@@ -50,7 +50,6 @@ if TYPE_CHECKING:
from backend.blocks._base import AnyBlockSchema
from .execution import NodesInputMasks
from .integrations import Webhook
logger = logging.getLogger(__name__)
@@ -141,12 +140,10 @@ class NodeModel(Node):
graph_version: int
webhook_id: Optional[str] = None
webhook: Optional["Webhook"] = None
# webhook: Optional["Webhook"] = None # deprecated
@staticmethod
def from_db(node: AgentNode, for_export: bool = False) -> "NodeModel":
from .integrations import Webhook
obj = NodeModel(
id=node.id,
block_id=node.agentBlockId,
@@ -155,7 +152,6 @@ class NodeModel(Node):
graph_id=node.agentGraphId,
graph_version=node.agentGraphVersion,
webhook_id=node.webhookId,
webhook=Webhook.from_db(node.Webhook) if node.Webhook else None,
)
obj.input_links = [Link.from_db(link) for link in node.Input or []]
obj.output_links = [Link.from_db(link) for link in node.Output or []]
@@ -188,7 +184,6 @@ class NodeModel(Node):
# Remove webhook info
stripped_node.webhook_id = None
stripped_node.webhook = None
return stripped_node

View File

@@ -323,7 +323,6 @@ async def test_clean_graph(server: SpinTestServer):
# Verify webhook info is removed (if any nodes had it)
for node in cleaned_graph.nodes:
assert node.webhook_id is None
assert node.webhook is None
@pytest.mark.asyncio(loop_scope="session")

View File

@@ -1,5 +1,5 @@
import logging
from typing import TYPE_CHECKING, AsyncGenerator, Literal, Optional, overload
from typing import AsyncGenerator, Literal, Optional, overload
from prisma.models import AgentNode, AgentPreset, IntegrationWebhook
from prisma.types import (
@@ -22,9 +22,6 @@ from backend.integrations.webhooks.utils import webhook_ingress_url
from backend.util.exceptions import NotFoundError
from backend.util.json import SafeJson
if TYPE_CHECKING:
from backend.api.features.library.model import LibraryAgentPreset
from .db import BaseDbModel
from .graph import NodeModel
@@ -75,11 +72,6 @@ class WebhookWithRelations(Webhook):
"AgentNodes and AgentPresets must be included in "
"IntegrationWebhook query with relations"
)
# LibraryAgentPreset import is moved to TYPE_CHECKING to avoid circular import:
# integrations.py → library/model.py → integrations.py (for Webhook)
# Runtime import is used in WebhookWithRelations.from_db() method instead
# Import at runtime to avoid circular dependency
from backend.api.features.library.model import LibraryAgentPreset
return WebhookWithRelations(
**Webhook.from_db(webhook).model_dump(),
@@ -90,6 +82,11 @@ class WebhookWithRelations(Webhook):
)
# LibraryAgentPreset import must be after WebhookWithRelations definition to avoid
# broken circular import:
# integrations.py → library/model.py → integrations.py (for Webhook)
from backend.api.features.library.model import LibraryAgentPreset # noqa: E402
# --------------------- CRUD functions --------------------- #

View File

@@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional, cast, overload
from backend.blocks._base import BlockSchema
from backend.data.graph import set_node_webhook
from backend.data.integrations import get_webhook
from backend.integrations.creds_manager import IntegrationCredentialsManager
from . import get_webhook_manager, supports_webhooks
@@ -113,31 +114,32 @@ async def on_node_deactivate(
webhooks_manager = get_webhook_manager(provider)
if node.webhook_id:
logger.debug(f"Node #{node.id} has webhook_id {node.webhook_id}")
if not node.webhook:
logger.error(f"Node #{node.id} has webhook_id but no webhook object")
raise ValueError("node.webhook not included")
if webhook_id := node.webhook_id:
logger.warning(
f"Node #{node.id} still attached to webhook #{webhook_id} - "
"did migration by `migrate_legacy_triggered_graphs` fail? "
"Triggered nodes are deprecated since Significant-Gravitas/AutoGPT#10418."
)
webhook = await get_webhook(webhook_id)
# Detach webhook from node
logger.debug(f"Detaching webhook from node #{node.id}")
updated_node = await set_node_webhook(node.id, None)
# Prune and deregister the webhook if it is no longer used anywhere
webhook = node.webhook
logger.debug(
f"Pruning{' and deregistering' if credentials else ''} "
f"webhook #{webhook.id}"
f"webhook #{webhook_id}"
)
await webhooks_manager.prune_webhook_if_dangling(
user_id, webhook.id, credentials
user_id, webhook_id, credentials
)
if (
cast(BlockSchema, block.input_schema).get_credentials_fields()
and not credentials
):
logger.warning(
f"Cannot deregister webhook #{webhook.id}: credentials "
f"Cannot deregister webhook #{webhook_id}: credentials "
f"#{webhook.credentials_id} not available "
f"({webhook.provider.value} webhook ID: {webhook.provider_webhook_id})"
)