Repository: Significant-Gravitas/Auto-GPT
File: autogpt_platform/backend/backend/data/execution.py (Python)

Code before:
) -> GraphExecution | None:
    res = await AgentGraphExecution.prisma().update(
        where={"id": graph_exec_id},
        data={
            "executionStatus": ExecutionStatus.RUNNING,
            "startedAt": datetime.now(tz=timezone.utc),
        },
        include=GRAPH_EXECUTION_INCLUDE,
    )
    return GraphExecution.from_db(res) if res else None


async def update_graph_execution_stats(
    graph_exec_id: str,
    status: ExecutionStatus,
    stats: GraphExecutionStats | None = None,
) -> GraphExecution | None:
    update_data: AgentGraphExecutionUpdateManyMutationInput = {
        "executionStatus": status
    }

    if stats:
        _stats = stats.model_dump()
        if isinstance(_stats.get("error"), Exception):
            _stats["error"] = str(_stats["error"])
        update_data["stats"] = Json(_stats)

    updated_count = await AgentGraphExecution.prisma().update_many(
        where={
            "id": graph_exec_id,
            "OR": [
                {"executionStatus": ExecutionStatus.RUNNING},
                {"executionStatus": ExecutionStatus.QUEUED},
            ],
        },
        data=update_data,
    )
    if updated_count == 0:
        return None

    graph_exec = await AgentGraphExecution.prisma().find_unique_or_raise(
        where={"id": graph_exec_id},
        include=GRAPH_EXECUTION_INCLUDE,
    )
    return GraphExecution.from_db(graph_exec)


async def update_node_execution_stats(node_exec_id: str, stats: NodeExecutionStats):
    data = stats.model_dump()
    if isinstance(data["error"], Exception):
        data["error"] = str(data["error"])

Review comment (suggestion):
nit, `_` prefix has special meaning and doesn't really fit here, so if not `data` like before maybe:
```suggestion
        stats_dict = stats.model_dump()
        if isinstance(stats_dict.get("error"), Exception):
            stats_dict["error"] = str(stats_dict["error"])
        update_data["stats"] = Json(stats_dict)
```

Code after:
) -> GraphExecution | None:
    res = await AgentGraphExecution.prisma().update(
        where={"id": graph_exec_id},
        data={
            "executionStatus": ExecutionStatus.RUNNING,
            "startedAt": datetime.now(tz=timezone.utc),
        },
        include=GRAPH_EXECUTION_INCLUDE,
    )
    return GraphExecution.from_db(res) if res else None


async def update_graph_execution_stats(
    graph_exec_id: str,
    status: ExecutionStatus,
    stats: GraphExecutionStats | None = None,
) -> GraphExecution | None:
    update_data: AgentGraphExecutionUpdateManyMutationInput = {
        "executionStatus": status
    }

    if stats:
        stats_dict = stats.model_dump()
        if isinstance(stats_dict.get("error"), Exception):
            stats_dict["error"] = str(stats_dict["error"])
        update_data["stats"] = Json(stats_dict)

    updated_count = await AgentGraphExecution.prisma().update_many(
        where={
            "id": graph_exec_id,
            "OR": [
                {"executionStatus": ExecutionStatus.RUNNING},
                {"executionStatus": ExecutionStatus.QUEUED},
            ],
        },
        data=update_data,
    )
    if updated_count == 0:
        return None

    graph_exec = await AgentGraphExecution.prisma().find_unique_or_raise(
        where={"id": graph_exec_id},
        include=GRAPH_EXECUTION_INCLUDE,
    )
    return GraphExecution.from_db(graph_exec)


async def update_node_execution_stats(node_exec_id: str, stats: NodeExecutionStats):
    data = stats.model_dump()
    if isinstance(data["error"], Exception):
        data["error"] = str(data["error"])