AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(backend): Include webhook block executions in `GraphExecution` queries (#9984)
Reinier van der Leerb244726b20ab
diff --git a/autogpt_platform/backend/backend/data/block.py b/autogpt_platform/backend/backend/data/block.pyindex 7b16928549..eca44fd7cd 100644--- a/autogpt_platform/backend/backend/data/block.py+++ b/autogpt_platform/backend/backend/data/block.py@@ -1,3 +1,4 @@+import functoolsimport inspectfrom abc import ABC, abstractmethodfrom enum import Enum@@ -8,6 +9,7 @@ from typing import (Generator,Generic,Optional,+ Sequence,Type,TypeVar,cast,@@ -523,3 +525,21 @@ async def initialize_blocks() -> None:def get_block(block_id: str) -> Block[BlockSchema, BlockSchema] | None:cls = get_blocks().get(block_id)return cls() if cls else None+++def get_webhook_block_ids() -> Sequence[str]:+ return [+ id+ for id, B in get_blocks().items()+ if B().block_type in (BlockType.WEBHOOK, BlockType.WEBHOOK_MANUAL)+ ]+++def get_io_block_ids() -> Sequence[str]:+ return [+ id+ for id, B in get_blocks().items()+ if B().block_type in (BlockType.INPUT, BlockType.OUTPUT)+ ]diff --git a/autogpt_platform/backend/backend/data/execution.py b/autogpt_platform/backend/backend/data/execution.pyindex 166a53a4ed..d27e427566 100644--- a/autogpt_platform/backend/backend/data/execution.py+++ b/autogpt_platform/backend/backend/data/execution.py@@ -38,12 +38,19 @@ from backend.server.v2.store.exceptions import DatabaseErrorfrom backend.util import type as type_utilsfrom backend.util.settings import Config-from .block import BlockInput, BlockType, CompletedBlockOutput, get_block+from .block import (+ BlockInput,+ BlockType,+ CompletedBlockOutput,+ get_block,+ get_io_block_ids,+ get_webhook_block_ids,+)from .db import BaseDbModelfrom .includes import (EXECUTION_RESULT_INCLUDE,- GRAPH_EXECUTION_INCLUDE,GRAPH_EXECUTION_INCLUDE_WITH_NODES,+ graph_execution_include,)from .model import CredentialsMetaInput, GraphExecutionStats, NodeExecutionStatsfrom .queue import AsyncRedisEventBus, RedisEventBus@@ -411,7 +418,9 @@ async def get_graph_execution(include=(GRAPH_EXECUTION_INCLUDE_WITH_NODESif include_node_executions- else GRAPH_EXECUTION_INCLUDE+ else graph_execution_include(+ [*get_io_block_ids(), *get_webhook_block_ids()]+ )),)if not execution:@@ -568,7 +577,9 @@ async def update_graph_execution_start_time("executionStatus": ExecutionStatus.RUNNING,"startedAt": datetime.now(tz=timezone.utc),},- include=GRAPH_EXECUTION_INCLUDE,+ include=graph_execution_include(+ [*get_io_block_ids(), *get_webhook_block_ids()]+ ),)return GraphExecution.from_db(res) if res else None@@ -603,7 +614,9 @@ async def update_graph_execution_stats(graph_exec = await AgentGraphExecution.prisma().find_unique_or_raise(where={"id": graph_exec_id},- include=GRAPH_EXECUTION_INCLUDE,+ include=graph_execution_include(+ [*get_io_block_ids(), *get_webhook_block_ids()]+ ),)return GraphExecution.from_db(graph_exec)diff --git a/autogpt_platform/backend/backend/data/includes.py b/autogpt_platform/backend/backend/data/includes.pyindex f6b1ea2592..d763579d91 100644--- a/autogpt_platform/backend/backend/data/includes.py+++ b/autogpt_platform/backend/backend/data/includes.py@@ -1,10 +1,8 @@-from typing import cast+from typing import Sequence, castimport prisma.enumsimport prisma.types-from backend.blocks.io import IO_BLOCK_IDs-AGENT_NODE_INCLUDE: prisma.types.AgentNodeInclude = {"Input": True,"Output": True,@@ -42,18 +40,26 @@ GRAPH_EXECUTION_INCLUDE_WITH_NODES: prisma.types.AgentGraphExecutionInclude = {}}-GRAPH_EXECUTION_INCLUDE: prisma.types.AgentGraphExecutionInclude = {- "NodeExecutions": {- **cast(- prisma.types.FindManyAgentNodeExecutionArgsFromAgentGraphExecution,- GRAPH_EXECUTION_INCLUDE_WITH_NODES["NodeExecutions"],- ),- "where": {- "Node": {"is": {"AgentBlock": {"is": {"id": {"in": IO_BLOCK_IDs}}}}},- "NOT": [{"executionStatus": prisma.enums.AgentExecutionStatus.INCOMPLETE}],- },++def graph_execution_include(+ include_block_ids: Sequence[str],+) -> prisma.types.AgentGraphExecutionInclude:+ return {+ "NodeExecutions": {+ **cast(+ prisma.types.FindManyAgentNodeExecutionArgsFromAgentGraphExecution,+ GRAPH_EXECUTION_INCLUDE_WITH_NODES["NodeExecutions"], # type: ignore+ ),+ "where": {+ "Node": {+ "is": {"AgentBlock": {"is": {"id": {"in": include_block_ids}}}}+ },+ "NOT": [+ {"executionStatus": prisma.enums.AgentExecutionStatus.INCOMPLETE}+ ],+ },+ }}-}INTEGRATION_WEBHOOK_INCLUDE: prisma.types.IntegrationWebhookInclude = {