Skip to content

Commit 54550f0

Browse files
fix(docs): async samples missing await (#2577)
Co-authored-by: Victor Chudnovsky <vchudnov@google.com>
1 parent 9cc7d37 commit 54550f0

File tree

40 files changed

+207
-138
lines changed

40 files changed

+207
-138
lines changed

gapic/templates/examples/feature_fragments.j2

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ request=request
230230
{# Note: this doesn't deal with enums or unions #}
231231
{# LROs return operation objects and paged requests return pager objects #}
232232
{% if transport == "grpc-async" and calling_form not in
233-
[calling_form_enum.LongRunningRequestPromise, calling_form_enum.RequestPagedAll] %}
233+
[calling_form_enum.RequestPaged, calling_form_enum.RequestPagedAll] %}
234234
await{{ " "}}
235235
{%- endif -%}
236236
{% if calling_form in [calling_form_enum.RequestStreamingBidi,
@@ -242,13 +242,6 @@ client.{{ render_method_name(sample)|trim }}({{ render_request_params_unary(samp
242242
{% endif %}
243243
{% endmacro %}
244244

245-
{% macro operation_text(transport) %}
246-
{% if transport == "grpc-async" %}
247-
(await operation)
248-
{% else %}
249-
operation
250-
{% endif %}
251-
{% endmacro %}
252245

253246
{# Setting up the method invocation is the responsibility of the caller: #}
254247
{# it's just easier to set up client side streaming and other things from outside this macro. #}
@@ -294,9 +287,7 @@ operation = {{ method_invocation_text|trim }}
294287

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

297-
{% with operation_text = operation_text(transport) %}
298-
response = {{ operation_text|trim }}.result()
299-
{% endwith %}
290+
response = {% if transport == "grpc-async" %}await {% endif %}operation.result()
300291

301292
# Handle the response
302293
{% for statement in response_statements %}

tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/async_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,11 @@ async def sample_export_assets():
322322
)
323323
324324
# Make the request
325-
operation = client.export_assets(request=request)
325+
operation = await client.export_assets(request=request)
326326
327327
print("Waiting for operation to complete...")
328328
329-
response = (await operation).result()
329+
response = await operation.result()
330330
331331
# Handle the response
332332
print(response)
@@ -1727,11 +1727,11 @@ async def sample_analyze_iam_policy_longrunning():
17271727
)
17281728
17291729
# Make the request
1730-
operation = client.analyze_iam_policy_longrunning(request=request)
1730+
operation = await client.analyze_iam_policy_longrunning(request=request)
17311731
17321732
print("Waiting for operation to complete...")
17331733
1734-
response = (await operation).result()
1734+
response = await operation.result()
17351735
17361736
# Handle the response
17371737
print(response)

tests/integration/goldens/asset/samples/generated_samples/cloudasset_v1_generated_asset_service_analyze_iam_policy_longrunning_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ async def sample_analyze_iam_policy_longrunning():
5151
)
5252

5353
# Make the request
54-
operation = client.analyze_iam_policy_longrunning(request=request)
54+
operation = await client.analyze_iam_policy_longrunning(request=request)
5555

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

58-
response = (await operation).result()
58+
response = await operation.result()
5959

6060
# Handle the response
6161
print(response)

tests/integration/goldens/asset/samples/generated_samples/cloudasset_v1_generated_asset_service_export_assets_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ async def sample_export_assets():
4848
)
4949

5050
# Make the request
51-
operation = client.export_assets(request=request)
51+
operation = await client.export_assets(request=request)
5252

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

55-
response = (await operation).result()
55+
response = await operation.result()
5656

5757
# Handle the response
5858
print(response)

tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -564,11 +564,11 @@ async def sample_create_trigger():
564564
)
565565
566566
# Make the request
567-
operation = client.create_trigger(request=request)
567+
operation = await client.create_trigger(request=request)
568568
569569
print("Waiting for operation to complete...")
570570
571-
response = (await operation).result()
571+
response = await operation.result()
572572
573573
# Handle the response
574574
print(response)
@@ -703,11 +703,11 @@ async def sample_update_trigger():
703703
)
704704
705705
# Make the request
706-
operation = client.update_trigger(request=request)
706+
operation = await client.update_trigger(request=request)
707707
708708
print("Waiting for operation to complete...")
709709
710-
response = (await operation).result()
710+
response = await operation.result()
711711
712712
# Handle the response
713713
print(response)
@@ -845,11 +845,11 @@ async def sample_delete_trigger():
845845
)
846846
847847
# Make the request
848-
operation = client.delete_trigger(request=request)
848+
operation = await client.delete_trigger(request=request)
849849
850850
print("Waiting for operation to complete...")
851851
852-
response = (await operation).result()
852+
response = await operation.result()
853853
854854
# Handle the response
855855
print(response)
@@ -1218,11 +1218,11 @@ async def sample_create_channel():
12181218
)
12191219
12201220
# Make the request
1221-
operation = client.create_channel(request=request)
1221+
operation = await client.create_channel(request=request)
12221222
12231223
print("Waiting for operation to complete...")
12241224
1225-
response = (await operation).result()
1225+
response = await operation.result()
12261226
12271227
# Handle the response
12281228
print(response)
@@ -1359,11 +1359,11 @@ async def sample_update_channel():
13591359
)
13601360
13611361
# Make the request
1362-
operation = client.update_channel(request=request)
1362+
operation = await client.update_channel(request=request)
13631363
13641364
print("Waiting for operation to complete...")
13651365
1366-
response = (await operation).result()
1366+
response = await operation.result()
13671367
13681368
# Handle the response
13691369
print(response)
@@ -1493,11 +1493,11 @@ async def sample_delete_channel():
14931493
)
14941494
14951495
# Make the request
1496-
operation = client.delete_channel(request=request)
1496+
operation = await client.delete_channel(request=request)
14971497
14981498
print("Waiting for operation to complete...")
14991499
1500-
response = (await operation).result()
1500+
response = await operation.result()
15011501
15021502
# Handle the response
15031503
print(response)
@@ -2084,11 +2084,11 @@ async def sample_create_channel_connection():
20842084
)
20852085
20862086
# Make the request
2087-
operation = client.create_channel_connection(request=request)
2087+
operation = await client.create_channel_connection(request=request)
20882088
20892089
print("Waiting for operation to complete...")
20902090
2091-
response = (await operation).result()
2091+
response = await operation.result()
20922092
20932093
# Handle the response
20942094
print(response)
@@ -2225,11 +2225,11 @@ async def sample_delete_channel_connection():
22252225
)
22262226
22272227
# Make the request
2228-
operation = client.delete_channel_connection(request=request)
2228+
operation = await client.delete_channel_connection(request=request)
22292229
22302230
print("Waiting for operation to complete...")
22312231
2232-
response = (await operation).result()
2232+
response = await operation.result()
22332233
22342234
# Handle the response
22352235
print(response)

tests/integration/goldens/eventarc/samples/generated_samples/eventarc_v1_generated_eventarc_create_channel_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ async def sample_create_channel():
5151
)
5252

5353
# Make the request
54-
operation = client.create_channel(request=request)
54+
operation = await client.create_channel(request=request)
5555

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

58-
response = (await operation).result()
58+
response = await operation.result()
5959

6060
# Handle the response
6161
print(response)

tests/integration/goldens/eventarc/samples/generated_samples/eventarc_v1_generated_eventarc_create_channel_connection_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ async def sample_create_channel_connection():
5050
)
5151

5252
# Make the request
53-
operation = client.create_channel_connection(request=request)
53+
operation = await client.create_channel_connection(request=request)
5454

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

57-
response = (await operation).result()
57+
response = await operation.result()
5858

5959
# Handle the response
6060
print(response)

tests/integration/goldens/eventarc/samples/generated_samples/eventarc_v1_generated_eventarc_create_trigger_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ async def sample_create_trigger():
5454
)
5555

5656
# Make the request
57-
operation = client.create_trigger(request=request)
57+
operation = await client.create_trigger(request=request)
5858

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

61-
response = (await operation).result()
61+
response = await operation.result()
6262

6363
# Handle the response
6464
print(response)

tests/integration/goldens/eventarc/samples/generated_samples/eventarc_v1_generated_eventarc_delete_channel_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ async def sample_delete_channel():
4545
)
4646

4747
# Make the request
48-
operation = client.delete_channel(request=request)
48+
operation = await client.delete_channel(request=request)
4949

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

52-
response = (await operation).result()
52+
response = await operation.result()
5353

5454
# Handle the response
5555
print(response)

tests/integration/goldens/eventarc/samples/generated_samples/eventarc_v1_generated_eventarc_delete_channel_connection_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ async def sample_delete_channel_connection():
4444
)
4545

4646
# Make the request
47-
operation = client.delete_channel_connection(request=request)
47+
operation = await client.delete_channel_connection(request=request)
4848

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

51-
response = (await operation).result()
51+
response = await operation.result()
5252

5353
# Handle the response
5454
print(response)

0 commit comments

Comments
 (0)