Skip to content

fix: Support pipe operator (X | Y) union syntax in function parameter parser#4405

Open
AhrendsW wants to merge 1 commit intogoogle:mainfrom
AhrendsW:fix/pipe-union-parser
Open

fix: Support pipe operator (X | Y) union syntax in function parameter parser#4405
AhrendsW wants to merge 1 commit intogoogle:mainfrom
AhrendsW:fix/pipe-union-parser

Conversation

@AhrendsW
Copy link

@AhrendsW AhrendsW commented Feb 7, 2026

Summary

  • Fixes Error adk_web_server.py:1431 - Error in event_generator: Failed to parse the parameter file_patterns: List[str] | None = None of function cleanup_unused_files #3591 — The function parameter parser did not recognize types.UnionType (created by Python 3.10+ pipe syntax like list[str] | None), only typing.Union. This caused a ValueError and fallback to Pydantic, which didn't always work (e.g., in the web builder).
  • Adds types.UnionType checks in three conditions within _parse_schema_from_parameter() in _function_parameter_parse_util.py:
    1. Simple union handler (get_origin check)
    2. Outer isinstance guard for the GenericAlias block
    3. Inner union check inside the GenericAlias block
  • Adds 8 new tests covering pipe union variants (optional list/dict, defaults, simple primitives, complex multi-type, GEMINI_API fallback, and typing.Union regression)

Test plan

  • All 43 tests in test_build_function_declaration.py pass
  • Full unittest suite passes (4017 passed, 0 failures)
  • pyink and isort formatting verified via autoformat.sh
  • Lint checks pass (pyink --check reports no changes needed)
  • No merge conflicts with main

… parser

The parser only recognized `typing.Union` but not `types.UnionType`
(created by Python 3.10+ pipe syntax like `list[str] | None`), causing
a ValueError fallback. This adds `types.UnionType` checks in three
conditions within `_parse_schema_from_parameter()`.

Fixes google#3591
@gemini-code-assist
Copy link
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@adk-bot adk-bot added the tools [Component] This issue is related to tools label Feb 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tools [Component] This issue is related to tools

Projects

None yet

2 participants