Skip to content

Commit 7d197db

Browse files
authored
fix(proto): use field.label instead of is_repeated for protobuf compatibility (#1010)
# Description Replace `field.is_repeated` with `field.label == field.LABEL_REPEATED` in `proto_utils.py` to support older protobuf versions where the `is_repeated` attribute is not available on `FieldDescriptor`. # Problem When using older protobuf versions accessing `field.is_repeated` raises: `a2a.utils.errors.InternalError: 'google._upb._message.FieldDescriptor' object has no attribute 'is_repeated'` The project's declared minimum is `protobuf>=5.29.5`, `5.29.5` does not support `is_repeated`. This caused `send_message` (and other proto-validating client calls) to fail at runtime for users on older protobuf releases. The `is_repeated` property was only added to `FieldDescriptor` in newer protobuf releases (6.x), so relying on it broke compatibility with the supported version range. Although the deprecated label was already [removed in some 7.x version](https://github.com/protocolbuffers/protobuf/releases/tag/v34.0-rc1.1), 7.x version can't be resolved with the other constraints we have in the project. # Fix Use the long-standing `label` attribute and compare against `FieldDescriptor.LABEL_REPEATED`, which is available across all supported protobuf versions and is the canonical way to detect repeated fields. # Testing - `uv run pytest` passes against the supported protobuf version range.
1 parent b3d1ad6 commit 7d197db

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/a2a/utils/proto_utils.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,10 @@ def parse_params(params: QueryParams, message: ProtobufMessage) -> None:
174174
field = fields[k]
175175
v_list = params.getlist(k)
176176

177-
if field.label == field.LABEL_REPEATED:
177+
# TODO(https://github.com/a2aproject/a2a-python/issues/1011): Replace
178+
# deprecated `field.label` with `field.is_repeated` once the minimum
179+
# protobuf version requirement is bumped.
180+
if field.label == FieldDescriptor.LABEL_REPEATED:
178181
accumulated: list[Any] = []
179182
for v in v_list:
180183
if not v:
@@ -208,7 +211,10 @@ def _check_required_field_violation(
208211
) -> ValidationDetail | None:
209212
"""Check if a required field is missing or invalid."""
210213
val = getattr(msg, field.name)
211-
if field.is_repeated:
214+
# TODO(https://github.com/a2aproject/a2a-python/issues/1011): Replace
215+
# deprecated `field.label` with `field.is_repeated` once the minimum
216+
# protobuf version requirement is bumped.
217+
if field.label == FieldDescriptor.LABEL_REPEATED:
212218
if not val:
213219
return ValidationDetail(
214220
field=field.name,
@@ -249,7 +255,10 @@ def _recurse_validation(
249255
return errors
250256

251257
val = getattr(msg, field.name)
252-
if not field.is_repeated:
258+
# TODO(https://github.com/a2aproject/a2a-python/issues/1011): Replace
259+
# deprecated `field.label` with `field.is_repeated` once the minimum
260+
# protobuf version requirement is bumped.
261+
if field.label != FieldDescriptor.LABEL_REPEATED:
253262
if msg.HasField(field.name):
254263
sub_errs = _validate_proto_required_fields_internal(val)
255264
_append_nested_errors(errors, field.name, sub_errs)

0 commit comments

Comments
 (0)