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: resolve rare issue where ValueError is not raised when both request and flattened param are set #2258

Closed
wants to merge 4 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
{% if method.flattened_fields %}
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([{{ method.flattened_fields.values()|join(", ", attribute="name") }}])
flattened_params = [{{ method.flattened_fields.values()|join(", ", attribute="name") }}]
has_flattened_params = len([param for param in flattened_params if param is not None]) > 0
if request is not None and has_flattened_params:
raise ValueError('If the `request` argument is set, then none of '
'the individual field arguments should be set.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@
{% if method.flattened_fields %}
# - Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([{{ method.flattened_fields.values()|join(", ", attribute="name") }}])
flattened_params = [{{ method.flattened_fields.values()|join(", ", attribute="name") }}]
has_flattened_params = len([param for param in flattened_params if param is not None]) > 0
if request is not None and has_flattened_params:
raise ValueError('If the `request` argument is set, then none of '
'the individual field arguments should be set.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ class {{ service.async_client_name }}:
{% if method.flattened_fields %}
# - Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([{{ method.flattened_fields.values()|join(", ", attribute="name") }}])
flattened_params = [{{ method.flattened_fields.values()|join(", ", attribute="name") }}]
has_flattened_params = len([param for param in flattened_params if param is not None]) > 0
if request is not None and has_flattened_params:
raise ValueError("If the `request` argument is set, then none of "
"the individual field arguments should be set.")
Expand Down
41 changes: 41 additions & 0 deletions tests/fragments/test_nested_messages.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (C) 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
syntax = "proto3";

package google.fragment;

import "google/protobuf/struct.proto";
import "google/api/client.proto";

service MyServiceWithNestedMessages {
option (google.api.default_host) = "my.example.com";

rpc MyMethod(MethodRequest) returns (MethodResponse) {
option (google.api.method_signature) = "some_message";
}
}

message AnotherMessage {};

message SomeMessage{
AnotherMessage another_message = 1;
}

message MethodRequest {
SomeMessage some_message = 1;
}

message MethodResponse {
google.protobuf.Value result = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ async def sample_list_assets():
# Create or coerce a protobuf request object.
# - Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([parent])
flattened_params = [parent]
has_flattened_params = len([param for param in flattened_params if param is not None]) > 0
if request is not None and has_flattened_params:
raise ValueError("If the `request` argument is set, then none of "
"the individual field arguments should be set.")
Expand Down Expand Up @@ -652,7 +653,8 @@ async def sample_create_feed():
# Create or coerce a protobuf request object.
# - Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([parent])
flattened_params = [parent]
has_flattened_params = len([param for param in flattened_params if param is not None]) > 0
if request is not None and has_flattened_params:
raise ValueError("If the `request` argument is set, then none of "
"the individual field arguments should be set.")
Expand Down Expand Up @@ -762,7 +764,8 @@ async def sample_get_feed():
# Create or coerce a protobuf request object.
# - Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([name])
flattened_params = [name]
has_flattened_params = len([param for param in flattened_params if param is not None]) > 0
if request is not None and has_flattened_params:
raise ValueError("If the `request` argument is set, then none of "
"the individual field arguments should be set.")
Expand Down Expand Up @@ -867,7 +870,8 @@ async def sample_list_feeds():
# Create or coerce a protobuf request object.
# - Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([parent])
flattened_params = [parent]
has_flattened_params = len([param for param in flattened_params if param is not None]) > 0
if request is not None and has_flattened_params:
raise ValueError("If the `request` argument is set, then none of "
"the individual field arguments should be set.")
Expand Down Expand Up @@ -981,7 +985,8 @@ async def sample_update_feed():
# Create or coerce a protobuf request object.
# - Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([feed])
flattened_params = [feed]
has_flattened_params = len([param for param in flattened_params if param is not None]) > 0
if request is not None and has_flattened_params:
raise ValueError("If the `request` argument is set, then none of "
"the individual field arguments should be set.")
Expand Down Expand Up @@ -1076,7 +1081,8 @@ async def sample_delete_feed():
# Create or coerce a protobuf request object.
# - Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([name])
flattened_params = [name]
has_flattened_params = len([param for param in flattened_params if param is not None]) > 0
if request is not None and has_flattened_params:
raise ValueError("If the `request` argument is set, then none of "
"the individual field arguments should be set.")
Expand Down Expand Up @@ -1288,7 +1294,8 @@ async def sample_search_all_resources():
# Create or coerce a protobuf request object.
# - Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([scope, query, asset_types])
flattened_params = [scope, query, asset_types]
has_flattened_params = len([param for param in flattened_params if param is not None]) > 0
if request is not None and has_flattened_params:
raise ValueError("If the `request` argument is set, then none of "
"the individual field arguments should be set.")
Expand Down Expand Up @@ -1481,7 +1488,8 @@ async def sample_search_all_iam_policies():
# Create or coerce a protobuf request object.
# - Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([scope, query])
flattened_params = [scope, query]
has_flattened_params = len([param for param in flattened_params if param is not None]) > 0
if request is not None and has_flattened_params:
raise ValueError("If the `request` argument is set, then none of "
"the individual field arguments should be set.")
Expand Down Expand Up @@ -2015,7 +2023,8 @@ async def sample_create_saved_query():
# Create or coerce a protobuf request object.
# - Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([parent, saved_query, saved_query_id])
flattened_params = [parent, saved_query, saved_query_id]
has_flattened_params = len([param for param in flattened_params if param is not None]) > 0
if request is not None and has_flattened_params:
raise ValueError("If the `request` argument is set, then none of "
"the individual field arguments should be set.")
Expand Down Expand Up @@ -2125,7 +2134,8 @@ async def sample_get_saved_query():
# Create or coerce a protobuf request object.
# - Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([name])
flattened_params = [name]
has_flattened_params = len([param for param in flattened_params if param is not None]) > 0
if request is not None and has_flattened_params:
raise ValueError("If the `request` argument is set, then none of "
"the individual field arguments should be set.")
Expand Down Expand Up @@ -2237,7 +2247,8 @@ async def sample_list_saved_queries():
# Create or coerce a protobuf request object.
# - Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([parent])
flattened_params = [parent]
has_flattened_params = len([param for param in flattened_params if param is not None]) > 0
if request is not None and has_flattened_params:
raise ValueError("If the `request` argument is set, then none of "
"the individual field arguments should be set.")
Expand Down Expand Up @@ -2363,7 +2374,8 @@ async def sample_update_saved_query():
# Create or coerce a protobuf request object.
# - Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([saved_query, update_mask])
flattened_params = [saved_query, update_mask]
has_flattened_params = len([param for param in flattened_params if param is not None]) > 0
if request is not None and has_flattened_params:
raise ValueError("If the `request` argument is set, then none of "
"the individual field arguments should be set.")
Expand Down Expand Up @@ -2462,7 +2474,8 @@ async def sample_delete_saved_query():
# Create or coerce a protobuf request object.
# - Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([name])
flattened_params = [name]
has_flattened_params = len([param for param in flattened_params if param is not None]) > 0
if request is not None and has_flattened_params:
raise ValueError("If the `request` argument is set, then none of "
"the individual field arguments should be set.")
Expand Down Expand Up @@ -2680,7 +2693,8 @@ async def sample_analyze_org_policies():
# Create or coerce a protobuf request object.
# - Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([scope, constraint, filter])
flattened_params = [scope, constraint, filter]
has_flattened_params = len([param for param in flattened_params if param is not None]) > 0
if request is not None and has_flattened_params:
raise ValueError("If the `request` argument is set, then none of "
"the individual field arguments should be set.")
Expand Down Expand Up @@ -2832,7 +2846,8 @@ async def sample_analyze_org_policy_governed_containers():
# Create or coerce a protobuf request object.
# - Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([scope, constraint, filter])
flattened_params = [scope, constraint, filter]
has_flattened_params = len([param for param in flattened_params if param is not None]) > 0
if request is not None and has_flattened_params:
raise ValueError("If the `request` argument is set, then none of "
"the individual field arguments should be set.")
Expand Down Expand Up @@ -3013,7 +3028,8 @@ async def sample_analyze_org_policy_governed_assets():
# Create or coerce a protobuf request object.
# - Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([scope, constraint, filter])
flattened_params = [scope, constraint, filter]
has_flattened_params = len([param for param in flattened_params if param is not None]) > 0
if request is not None and has_flattened_params:
raise ValueError("If the `request` argument is set, then none of "
"the individual field arguments should be set.")
Expand Down
Loading