Skip to content

Commit 474950f

Browse files
Simon Rosenbergclaude
andcommitted
fix: guard agent field serializer against None when profile-only request is dumped
`StartConversationRequest` with `agent_profile_id` set holds `agent=None` (the server resolves it). Pydantic's `model_dump` calls the `AgentBase` model_serializer with `self=None`, crashing. The `@field_serializer("agent", mode="wrap")` short-circuits before the model_serializer fires and returns `None` directly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c2b35a0 commit 474950f

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

  • openhands-sdk/openhands/sdk/conversation

openhands-sdk/openhands/sdk/conversation/request.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@
1111
from typing import Annotated, Any, Literal, cast
1212
from uuid import UUID
1313

14-
from pydantic import BaseModel, Discriminator, Field, Tag, model_validator
14+
from pydantic import (
15+
BaseModel,
16+
Discriminator,
17+
Field,
18+
Tag,
19+
field_serializer,
20+
model_validator,
21+
)
1522

1623
from openhands.sdk.agent.acp_agent import ACPAgent as ACPAgent
1724
from openhands.sdk.agent.agent import Agent as Agent
@@ -287,6 +294,12 @@ def _require_agent(self) -> StartConversationRequest:
287294
)
288295
return self
289296

297+
@field_serializer("agent", mode="wrap")
298+
def _serialize_agent(self, value: AgentBase | None, handler: Any) -> Any:
299+
if value is None:
300+
return None
301+
return handler(value)
302+
290303

291304
class StartACPConversationRequest(StartConversationRequest):
292305
"""Deprecated compatibility alias for ACP-capable start requests.

0 commit comments

Comments
 (0)