Skip to content

Type checkers reject Event convenience kwargs (route=, message=, state=, node_path=)聽#7623

Description

@yut0takagi

馃敶 Required Information

Describe the Bug:

Event accepts message=, state=, route= and node_path= in its
constructor, and the workflow samples use them. They are not Pydantic fields:
the mode='before' validator _accept_convenience_kwargs moves them into
content, actions.state_delta, actions.route and node_info.path. Static
type checkers only see the fields, so pyright reports every such call as an
error. contributing/samples/workflows alone has 59 of them (35 message,
13 state, 11 route).

Because Event uses extra='ignore', a misspelled keyword such as
Event(rout='next') is also dropped silently at runtime. A type checker is the
only tool that could catch it, but today it cannot tell the typo from the valid
keywords.

Steps to Reproduce:

  1. Install google-adk 2.12.0 (also reproduced on main 1def14b) and pyright
    1.1.407.
  2. Save the snippet under "Minimal Reproduction Code" as typo_check.py.
  3. Run pyright typo_check.py contributing/samples/workflows/route/agent.py.

Expected Behavior:

The four convenience kwargs type-check, and only the typo rout= is reported.

Observed Behavior:

contributing/samples/workflows/route/agent.py:28:16 - error: No parameter named "state" (reportCallIssue)
contributing/samples/workflows/route/agent.py:43:15 - error: No parameter named "route" (reportCallIssue)
contributing/samples/workflows/route/agent.py:60:7 - error: No parameter named "message" (reportCallIssue)
typo_check.py:3:7 - error: No parameter named "route" (reportCallIssue)
typo_check.py:3:21 - error: No parameter named "message" (reportCallIssue)
typo_check.py:3:35 - error: No parameter named "state" (reportCallIssue)
typo_check.py:3:51 - error: No parameter named "node_path" (reportCallIssue)
typo_check.py:4:7 - error: No parameter named "rout" (reportCallIssue)
8 errors, 0 warnings, 0 informations

mypy with the pydantic plugin accepts the convenience kwargs, but it also
accepts the typo, because Event allows extra keys.

Environment Details:

  • ADK Library Version (pip show google-adk): 2.12.0
  • Desktop OS: macOS
  • Python Version (python -V): 3.11.15

Model Information:

  • Are you using LiteLLM: N/A (no model call involved)
  • Which model is being used: N/A

馃煛 Optional Information

Minimal Reproduction Code:

from google.adk.events.event import Event

Event(route='next', message='hi', state={'k': 1}, node_path='a/b')
Event(rout='next')  # typo

How often has this issue occurred?:

  • Always (100%)

Additional Context:

A fix is proposed in #7622: a TYPE_CHECKING-only __init__ that lists the
fields and the four convenience kwargs, with a unit test that keeps it in sync
with Event.model_fields.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions