Skip to content

Event.model_validate mutates caller-provided input dict #6315

Description

@VectorPeak

Problem

Event._accept_convenience_kwargs() consumes convenience inputs such as message, state, route, and node_path in a mode="before" model validator.

When callers use Event.model_validate(payload) with a dict they still own, Pydantic passes that dict into the before validator. The validator currently calls pop() directly on that mapping, so validation rewrites the caller's original payload in place.

Minimal reproduction:

from google.adk.events.event import Event

payload = {
    "message": "Hello!",
    "state": {"key": "value"},
    "route": "next",
    "node_path": "root.node",
}

Event.model_validate(payload)
print(payload)

Current behavior: payload is mutated from the convenience-key shape into a canonical event shape containing content, actions, and node_info.

Expected behavior: validation should produce the canonical Event output without modifying the caller-provided input dictionary.

Impact

Callers that reuse the same payload for logging, retrying, comparing, or validating elsewhere can observe unexpected top-level mutation after Event.model_validate().

Proposed fix

Copy the incoming dict inside the before validator before consuming convenience keys. This preserves the existing routing behavior while avoiding mutation of caller-owned input.

Related PR

A focused fix and regression test are proposed in #6314.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions