Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unknown resources do not cause a generator crash #675

Merged
merged 2 commits into from
Oct 20, 2020
Merged
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
11 changes: 6 additions & 5 deletions gapic/schema/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,11 +1064,12 @@ def gen_indirect_resources_used(message):
resource = field.options.Extensions[
resource_pb2.resource_reference]
resource_type = resource.type or resource.child_type
# The common resources are defined (and rendered) explicitly
# by separate logic, and the resource definitions are never
# visible in any of the APIs file descriptor protos.
if resource_type and resource_type not in self.common_resources:
yield self.visible_resources[resource_type]
# The resource may not be visible if the resource type is one of
# the common_resources (see the class var in class definition)
# or if it's something unhelpful like '*'.
resource = self.visible_resources.get(resource_type)
if resource:
yield resource

return frozenset(
msg
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/schema/wrappers/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,30 @@ def test_resource_messages():
assert expected == actual


def test_service_unknown_resource_reference():
# This happens occasionally.
opts = descriptor_pb2.FieldOptions()
res_ref = opts.Extensions[resource_pb2.resource_reference]
res_ref.type = "*"
squid_request = make_message(
"CreateSquid",
fields=(
make_field("parent", type="TYPE_STRING", options=opts,),
),
)
squid_service = make_service(
"SquidService",
methods=(
make_method(
"CreateSquid",
input_message=squid_request,
),
),
)

assert not squid_service.resource_messages


def test_service_any_streaming():
for client, server in itertools.product((True, False), (True, False)):
service = make_service(
Expand Down