Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/google/adk/workflow/_retry_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from __future__ import annotations

from collections.abc import Sequence
from typing import Any

from pydantic import BaseModel
Expand Down Expand Up @@ -61,10 +62,15 @@ class RetryConfig(BaseModel):

@field_validator('exceptions', mode='before')
@classmethod
def _normalize_exceptions(cls, v: list[Any] | None) -> list[str] | None:
def _normalize_exceptions(cls, v: Any) -> list[str] | None:
"""Converts exception classes to their class names for uniform handling."""
if v is None:
return None
if isinstance(v, (str, bytes, bytearray)) or not isinstance(v, Sequence):
raise WorkflowConfigurationError(
'exceptions must be a sequence of exception class names (str) or'
f' exception classes, got {type(v).__name__}: {v!r}'
)
normalized = []
for item in v:
if isinstance(item, str):
Expand Down
24 changes: 24 additions & 0 deletions tests/unittests/workflow/utils/test_retry_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from google.adk.workflow.utils._retry_utils import _node_retry_config
from google.adk.workflow.utils._retry_utils import _should_retry_node
from google.adk.workflow.utils._retry_utils import _with_retry_config
from pydantic import ValidationError
import pytest


Expand Down Expand Up @@ -243,6 +244,29 @@ def test_configuration_and_invariant_errors_are_never_retried(
_should_retry_node(error, config, NodeState(attempt_count=1)) is False
)

@pytest.mark.parametrize(
"invalid_exceptions",
[
"ValueError",
b"ValueError",
ValueError,
123,
{"ValueError": True},
],
ids=["str", "bytes", "single_class", "int", "dict"],
)
def test_non_sequence_or_string_exceptions_raises_validation_error(
self, invalid_exceptions
) -> None:
"""Bare strings or non-sequence values must be rejected during validation.

Without an explicit guard, a bare string like ``"ValueError"`` is iterated
character-by-character into ``['V', 'a', ...]`` and silently never matches,
while non-iterable values like a bare exception class raise a raw TypeError.
"""
with pytest.raises(ValidationError, match="must be a sequence"):
RetryConfig(exceptions=invalid_exceptions)


class TestDelegatesItemRetry:

Expand Down