From 341f448ce378375ab79bfc82f864fb6c88ed71a0 Mon Sep 17 00:00:00 2001 From: kolea2 <45548808+kolea2@users.noreply.github.com> Date: Wed, 24 Feb 2021 14:32:10 -0500 Subject: [PATCH] fix: guard assignments of certain values against None (#220) * chore: manual regen of synth * cleanup --- .gitignore | 4 +++- .kokoro/build.sh | 10 ++++++++ .../bigtable_instance_admin/client.py | 14 ++++++++--- .../bigtable_instance_admin/pagers.py | 11 ++++++++- .../services/bigtable_table_admin/client.py | 14 ++++++++--- .../services/bigtable_table_admin/pagers.py | 11 ++++++++- .../bigtable_v2/services/bigtable/client.py | 24 ++++++++----------- synth.py | 8 +++++++ 8 files changed, 73 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index b9daa52f1..b4243ced7 100644 --- a/.gitignore +++ b/.gitignore @@ -50,8 +50,10 @@ docs.metadata # Virtual environment env/ + +# Test logs coverage.xml -sponge_log.xml +*sponge_log.xml # System test environment variables. system_tests/local_test_setup diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 76d9329ba..9773bfca7 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -40,6 +40,16 @@ python3 -m pip uninstall --yes --quiet nox-automation python3 -m pip install --upgrade --quiet nox python3 -m nox --version +# If this is a continuous build, send the test log to the FlakyBot. +# See https://github.com/googleapis/repo-automation-bots/tree/master/packages/flakybot. +if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"continuous"* ]]; then + cleanup() { + chmod +x $KOKORO_GFILE_DIR/linux_amd64/flakybot + $KOKORO_GFILE_DIR/linux_amd64/flakybot + } + trap cleanup EXIT HUP +fi + # If NOX_SESSION is set, it only runs the specified session, # otherwise run all the sessions. if [[ -n "${NOX_SESSION:-}" ]]; then diff --git a/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/client.py b/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/client.py index 8e6f504da..d7b1a778f 100644 --- a/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/client.py +++ b/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/client.py @@ -484,9 +484,8 @@ def create_instance( request.instance_id = instance_id if instance is not None: request.instance = instance - - if clusters: - request.clusters.update(clusters) + if clusters is not None: + request.clusters = clusters # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1832,6 +1831,9 @@ def get_iam_policy( elif not request: request = iam_policy.GetIamPolicyRequest(resource=resource,) + if resource is not None: + request.resource = resource + # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_iam_policy] @@ -1957,6 +1959,9 @@ def set_iam_policy( elif not request: request = iam_policy.SetIamPolicyRequest(resource=resource,) + if resource is not None: + request.resource = resource + # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.set_iam_policy] @@ -2039,6 +2044,9 @@ def test_iam_permissions( resource=resource, permissions=permissions, ) + if resource is not None: + request.resource = resource + # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.test_iam_permissions] diff --git a/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/pagers.py b/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/pagers.py index f70936b5b..f92d47886 100644 --- a/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/pagers.py +++ b/google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/pagers.py @@ -15,7 +15,16 @@ # limitations under the License. # -from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple +from typing import ( + Any, + AsyncIterable, + Awaitable, + Callable, + Iterable, + Sequence, + Tuple, + Optional, +) from google.cloud.bigtable_admin_v2.types import bigtable_instance_admin from google.cloud.bigtable_admin_v2.types import instance diff --git a/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/client.py b/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/client.py index 58eb4a9cd..de3146116 100644 --- a/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/client.py +++ b/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/client.py @@ -952,9 +952,8 @@ def modify_column_families( if name is not None: request.name = name - - if modifications: - request.modifications.extend(modifications) + if modifications is not None: + request.modifications = modifications # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2236,6 +2235,9 @@ def get_iam_policy( elif not request: request = iam_policy.GetIamPolicyRequest(resource=resource,) + if resource is not None: + request.resource = resource + # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.get_iam_policy] @@ -2361,6 +2363,9 @@ def set_iam_policy( elif not request: request = iam_policy.SetIamPolicyRequest(resource=resource,) + if resource is not None: + request.resource = resource + # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.set_iam_policy] @@ -2443,6 +2448,9 @@ def test_iam_permissions( resource=resource, permissions=permissions, ) + if resource is not None: + request.resource = resource + # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.test_iam_permissions] diff --git a/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/pagers.py b/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/pagers.py index be7c121d7..203d94f83 100644 --- a/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/pagers.py +++ b/google/cloud/bigtable_admin_v2/services/bigtable_table_admin/pagers.py @@ -15,7 +15,16 @@ # limitations under the License. # -from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple +from typing import ( + Any, + AsyncIterable, + Awaitable, + Callable, + Iterable, + Sequence, + Tuple, + Optional, +) from google.cloud.bigtable_admin_v2.types import bigtable_table_admin from google.cloud.bigtable_admin_v2.types import table diff --git a/google/cloud/bigtable_v2/services/bigtable/client.py b/google/cloud/bigtable_v2/services/bigtable/client.py index 8ae811054..a9f3dfd74 100644 --- a/google/cloud/bigtable_v2/services/bigtable/client.py +++ b/google/cloud/bigtable_v2/services/bigtable/client.py @@ -621,12 +621,11 @@ def mutate_row( request.table_name = table_name if row_key is not None: request.row_key = row_key + if mutations is not None: + request.mutations = mutations if app_profile_id is not None: request.app_profile_id = app_profile_id - if mutations: - request.mutations.extend(mutations) - # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.mutate_row] @@ -730,12 +729,11 @@ def mutate_rows( if table_name is not None: request.table_name = table_name + if entries is not None: + request.entries = entries if app_profile_id is not None: request.app_profile_id = app_profile_id - if entries: - request.entries.extend(entries) - # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.mutate_rows] @@ -881,14 +879,13 @@ def check_and_mutate_row( request.row_key = row_key if predicate_filter is not None: request.predicate_filter = predicate_filter + if true_mutations is not None: + request.true_mutations = true_mutations + if false_mutations is not None: + request.false_mutations = false_mutations if app_profile_id is not None: request.app_profile_id = app_profile_id - if true_mutations: - request.true_mutations.extend(true_mutations) - if false_mutations: - request.false_mutations.extend(false_mutations) - # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.check_and_mutate_row] @@ -1005,12 +1002,11 @@ def read_modify_write_row( request.table_name = table_name if row_key is not None: request.row_key = row_key + if rules is not None: + request.rules = rules if app_profile_id is not None: request.app_profile_id = app_profile_id - if rules: - request.rules.extend(rules) - # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.read_modify_write_row] diff --git a/synth.py b/synth.py index e2fda520a..2a74e80f6 100644 --- a/synth.py +++ b/synth.py @@ -47,6 +47,14 @@ s.move(library / "tests") s.move(library / "scripts") +# temporary workaround for https://github.com/googleapis/gapic-generator-python/issues/778 +s.replace( + "google/cloud/**/client.py", + """\s+if permissions: +\s+request\.permissions\.extend\(permissions\)""", + "", +) + # ---------------------------------------------------------------------------- # Add templated files # ----------------------------------------------------------------------------