Skip to content

Commit

Permalink
fix: snippetgen should call await on the operation coroutine before c…
Browse files Browse the repository at this point in the history
…alling result
  • Loading branch information
dizcology committed Nov 15, 2022
1 parent f8bc1c6 commit 28ffc51
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 25 deletions.
12 changes: 11 additions & 1 deletion gapic/templates/examples/feature_fragments.j2
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@ client.{{ sample.rpc|snake_case }}({{ render_request_params_unary(sample.request
{% endif %}
{% endmacro %}

{% macro operation_text(transport) %}
{% if transport == "grpc-async" %}
(await operation)
{% else %}
operation
{% endif %}
{% endmacro %}

{# Setting up the method invocation is the responsibility of the caller: #}
{# it's just easier to set up client side streaming and other things from outside this macro. #}
{% macro render_calling_form(method_invocation_text, calling_form, calling_form_enum, transport, response_statements ) %}
Expand Down Expand Up @@ -286,7 +294,9 @@ operation = {{ method_invocation_text|trim }}

print("Waiting for operation to complete...")

response = {% if transport == "grpc-async" %}await {% endif %}operation.result()
{% with operation_text = operation_text(transport) %}
response = {{ operation_text|trim }}.result()
{% endwith %}

# Handle the response
{% for statement in response_statements %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ async def sample_export_assets():
print("Waiting for operation to complete...")
response = await operation.result()
response = (await operation).result()
# Handle the response
print(response)
Expand Down Expand Up @@ -1610,7 +1610,7 @@ async def sample_analyze_iam_policy_longrunning():
print("Waiting for operation to complete...")
response = await operation.result()
response = (await operation).result()
# Handle the response
print(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async def sample_analyze_iam_policy_longrunning():

print("Waiting for operation to complete...")

response = await operation.result()
response = (await operation).result()

# Handle the response
print(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async def sample_export_assets():

print("Waiting for operation to complete...")

response = await operation.result()
response = (await operation).result()

# Handle the response
print(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ async def sample_create_trigger():
print("Waiting for operation to complete...")
response = await operation.result()
response = (await operation).result()
# Handle the response
print(response)
Expand Down Expand Up @@ -593,7 +593,7 @@ async def sample_update_trigger():
print("Waiting for operation to complete...")
response = await operation.result()
response = (await operation).result()
# Handle the response
print(response)
Expand Down Expand Up @@ -730,7 +730,7 @@ async def sample_delete_trigger():
print("Waiting for operation to complete...")
response = await operation.result()
response = (await operation).result()
# Handle the response
print(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async def sample_create_trigger():

print("Waiting for operation to complete...")

response = await operation.result()
response = (await operation).result()

# Handle the response
print(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async def sample_delete_trigger():

print("Waiting for operation to complete...")

response = await operation.result()
response = (await operation).result()

# Handle the response
print(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def sample_update_trigger():

print("Waiting for operation to complete...")

response = await operation.result()
response = (await operation).result()

# Handle the response
print(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ async def sample_create_instance():
print("Waiting for operation to complete...")
response = await operation.result()
response = (await operation).result()
# Handle the response
print(response)
Expand Down Expand Up @@ -643,7 +643,7 @@ async def sample_update_instance():
print("Waiting for operation to complete...")
response = await operation.result()
response = (await operation).result()
# Handle the response
print(response)
Expand Down Expand Up @@ -778,7 +778,7 @@ async def sample_upgrade_instance():
print("Waiting for operation to complete...")
response = await operation.result()
response = (await operation).result()
# Handle the response
print(response)
Expand Down Expand Up @@ -917,7 +917,7 @@ async def sample_import_instance():
print("Waiting for operation to complete...")
response = await operation.result()
response = (await operation).result()
# Handle the response
print(response)
Expand Down Expand Up @@ -1052,7 +1052,7 @@ async def sample_export_instance():
print("Waiting for operation to complete...")
response = await operation.result()
response = (await operation).result()
# Handle the response
print(response)
Expand Down Expand Up @@ -1181,7 +1181,7 @@ async def sample_failover_instance():
print("Waiting for operation to complete...")
response = await operation.result()
response = (await operation).result()
# Handle the response
print(response)
Expand Down Expand Up @@ -1309,7 +1309,7 @@ async def sample_delete_instance():
print("Waiting for operation to complete...")
response = await operation.result()
response = (await operation).result()
# Handle the response
print(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async def sample_create_instance():

print("Waiting for operation to complete...")

response = await operation.result()
response = (await operation).result()

# Handle the response
print(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def sample_delete_instance():

print("Waiting for operation to complete...")

response = await operation.result()
response = (await operation).result()

# Handle the response
print(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async def sample_export_instance():

print("Waiting for operation to complete...")

response = await operation.result()
response = (await operation).result()

# Handle the response
print(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def sample_failover_instance():

print("Waiting for operation to complete...")

response = await operation.result()
response = (await operation).result()

# Handle the response
print(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async def sample_import_instance():

print("Waiting for operation to complete...")

response = await operation.result()
response = (await operation).result()

# Handle the response
print(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def sample_update_instance():

print("Waiting for operation to complete...")

response = await operation.result()
response = (await operation).result()

# Handle the response
print(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async def sample_upgrade_instance():

print("Waiting for operation to complete...")

response = await operation.result()
response = (await operation).result()

# Handle the response
print(response)
Expand Down

0 comments on commit 28ffc51

Please sign in to comment.