Skip to content

Commit 9f5b22f

Browse files
committed
raise ValueError if response_message_cls is not a subclass of proto.Message or google.protobuf.message.Message
1 parent ad79bf0 commit 9f5b22f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

google/api_core/rest_streaming.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class ResponseIterator:
3131
response (requests.Response): An API response object.
3232
response_message_cls (Union[proto.Message, google.protobuf.message.Message]): A response
3333
class expected to be returned from an API.
34+
35+
Raises:
36+
ValueError: If `response_message_cls` is not a subclass of `proto.Message` or `google.protobuf.message.Message`.
3437
"""
3538

3639
def __init__(
@@ -116,8 +119,12 @@ def _grab(self):
116119
# Add extra quotes to make json.loads happy.
117120
if issubclass(self._response_message_cls, proto.Message):
118121
return self._response_message_cls.from_json(self._ready_objs.popleft())
119-
else:
122+
elif issubclass(self._response_message_cls, google.protobuf.message.Message):
120123
return Parse(self._ready_objs.popleft(), self._response_message_cls())
124+
else:
125+
raise ValueError(
126+
"Response message class must be a subclass of proto.Message or google.protobuf.message.Message."
127+
)
121128

122129
def __iter__(self):
123130
return self

0 commit comments

Comments
 (0)