diff --git a/gapic/ads-templates/%namespace/%name/%version/%sub/types/_message.py.j2 b/gapic/ads-templates/%namespace/%name/%version/%sub/types/_message.py.j2 index ea4d5eb25..86b128925 100644 --- a/gapic/ads-templates/%namespace/%name/%version/%sub/types/_message.py.j2 +++ b/gapic/ads-templates/%namespace/%name/%version/%sub/types/_message.py.j2 @@ -12,7 +12,7 @@ class {{ message.name }}({{ p }}.Message): {% endif %} {% endif %} {# Use select filter to capture nested values. See https://github.com/googleapis/gapic-generator-python/issues/1083 #} - {%- if message.fields.values() | map(attribute="oneof") | select | list %} + {%- if message.fields.values() | map(attribute="oneof", default="") | select | list %} .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields {% endif %} @@ -43,7 +43,7 @@ class {{ message.name }}({{ p }}.Message): {% endif %} {% endfor %} - {% if "next_page_token" in message.fields.values()|map(attribute='name') %} + {% if "next_page_token" in message.fields.values()|map(attribute='name', default="") %} @property def raw_page(self): return self diff --git a/gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 b/gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 index 5cc8a9b80..af148882f 100644 --- a/gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 +++ b/gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 @@ -607,7 +607,7 @@ def test_{{ method_name }}(request_type, transport: str = 'grpc'): for message in response: assert isinstance(message, {{ method.output.ident }}) {% else %} - {% if "next_page_token" in method.output.fields.values()|map(attribute='name') and not method.paged_result_field %} + {% if "next_page_token" in method.output.fields.values()|map(attribute='name', default="") and not method.paged_result_field %} {# Cheeser assertion to force code coverage for bad paginated methods #} assert response.raw_page is response {% endif %} @@ -1215,7 +1215,7 @@ def test_{{ method.name|snake_case }}_rest(request_type): response = client.{{ method_name }}(request) {% endif %} - {% if "next_page_token" in method.output.fields.values()|map(attribute='name') and not method.paged_result_field %} + {% if "next_page_token" in method.output.fields.values()|map(attribute='name', default="") and not method.paged_result_field %} {# Cheeser assertion to force code coverage for bad paginated methods #} assert response.raw_page is response diff --git a/gapic/templates/%namespace/%name_%version/%sub/types/_message.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/types/_message.py.j2 index eb2dc2399..714b9eead 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/types/_message.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/types/_message.py.j2 @@ -12,7 +12,7 @@ class {{ message.name }}({{ p }}.Message): {% endif %} {% endif %} {# Use select filter to capture nested values. See https://github.com/googleapis/gapic-generator-python/issues/1083 #} - {%- if message.fields.values() | map(attribute="oneof") | select | list %} + {%- if message.fields.values() | map(attribute="oneof", default="") | select | list %} .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields {% endif %} @@ -43,7 +43,7 @@ class {{ message.name }}({{ p }}.Message): {% endif %} {% endfor %} - {% if "next_page_token" in message.fields.values()|map(attribute='name') %} + {% if "next_page_token" in message.fields.values()|map(attribute='name', default="") %} @property def raw_page(self): return self diff --git a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2 b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2 index bae87184f..2b3c3a382 100644 --- a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2 +++ b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2 @@ -93,7 +93,7 @@ def test_{{ method_name }}(request_type, transport: str = 'grpc'): for message in response: assert isinstance(message, {{ method.output.ident }}) {% else %} - {% if "next_page_token" in method.output.fields.values()|map(attribute='name') and not method.paged_result_field %} + {% if "next_page_token" in method.output.fields.values()|map(attribute='name', default="") and not method.paged_result_field %} {# Cheeser assertion to force code coverage for bad paginated methods #} assert response.raw_page is response {% endif %} @@ -1278,7 +1278,7 @@ def test_{{ method_name }}_rest(request_type): response = client.{{ method_name }}(request) {% endif %} - {% if "next_page_token" in method_output.fields.values()|map(attribute='name') and not method.paged_result_field %} + {% if "next_page_token" in method_output.fields.values()|map(attribute='name', default="") and not method.paged_result_field %} {# Cheeser assertion to force code coverage for bad paginated methods #} assert response.raw_page is response