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): handle null values in GraphSettings validation (#11812)
Zamil Majdyb714c0c22164
diff --git a/autogpt_platform/backend/backend/data/graph.py b/autogpt_platform/backend/backend/data/graph.pyindex d868c0ff3b..d70bdbdc61 100644--- a/autogpt_platform/backend/backend/data/graph.py+++ b/autogpt_platform/backend/backend/data/graph.py@@ -3,7 +3,7 @@ import loggingimport uuidfrom collections import defaultdictfrom datetime import datetime, timezone-from typing import TYPE_CHECKING, Any, Literal, Optional, cast+from typing import TYPE_CHECKING, Annotated, Any, Literal, Optional, castfrom prisma.enums import SubmissionStatusfrom prisma.models import (@@ -20,7 +20,7 @@ from prisma.types import (AgentNodeLinkCreateInput,StoreListingVersionWhereInput,)-from pydantic import BaseModel, Field, create_model+from pydantic import BaseModel, BeforeValidator, Field, create_modelfrom pydantic.fields import computed_fieldfrom backend.blocks.agent import AgentExecutorBlock@@ -62,8 +62,14 @@ logger = logging.getLogger(__name__)class GraphSettings(BaseModel):- human_in_the_loop_safe_mode: bool = True- sensitive_action_safe_mode: bool = False+ # Use Annotated with BeforeValidator to coerce None to default values.+ # This handles cases where the database has null values for these fields.+ human_in_the_loop_safe_mode: Annotated[+ bool, BeforeValidator(lambda v: v if v is not None else True)+ ] = True+ sensitive_action_safe_mode: Annotated[+ bool, BeforeValidator(lambda v: v if v is not None else False)+ ] = False@classmethoddef from_graph(