From 57480019c3e77c6b3a85bdaf8441334170b318e8 Mon Sep 17 00:00:00 2001 From: Vadym Matsishevskyi <25311427+vam-google@users.noreply.github.com> Date: Fri, 7 May 2021 14:40:33 -0700 Subject: [PATCH] fix: Check for default value presence for non-optional fields in REST (#868) --- .../%sub/services/%service/transports/rest.py.j2 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 index e3622630a..24af43d76 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 @@ -195,14 +195,15 @@ class {{ service.name }}RestTransport({{ service.name }}Transport): if {{ method.input.ident }}.{{ field }} in request: query_params['{{ field|camel_case }}'] = request.{{ field }} {% else %} - query_params['{{ field|camel_case }}'] = request.{{ field }} + if request.{{ field }}: + query_params['{{ field|camel_case }}'] = request.{{ field }} {% endif %} {% endfor %} # TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here # discards default values # TODO(yon-mg): add test for proper url encoded strings - query_params = ['{k}={v}'.format(k=k, v=v) for k, v in query_params.items() if v] + query_params = ['{k}={v}'.format(k=k, v=v) for k, v in query_params.items()] url += '?{}'.format('&'.join(query_params)).replace(' ', '+') # Send the request