Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: snippetgen should call await on the operation coroutine before calling result #1495

Merged
merged 2 commits into from
Nov 16, 2022

Conversation

dizcology
Copy link
Collaborator

@dizcology dizcology commented Nov 15, 2022

Currently the generated snippet contains the following code for async client that returns a long running operation, such as Vision API's import_product_sets:

    ...
    operation = client.import_product_sets(request=request)
    ...
    response = await operation.result()
    ...

This is incorrect since operation is a coroutine that needs to be awaited to return an actual operation (which has the result attribute).

The proposed fix is to change the generated code to:

     response = (await operation).result()

@dizcology dizcology requested review from a team as code owners November 15, 2022 23:44
@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Nov 15, 2022
@dizcology dizcology force-pushed the snippetgen-fix-async-lro branch from 28ffc51 to cc6a6ca Compare November 15, 2022 23:46
@@ -239,7 +239,7 @@ async def sample_export_assets():

Copy link
Collaborator Author

@dizcology dizcology Nov 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative is to change the line above to the following (add await before the method call):

operation = await client.export_assets(request=request)

@dizcology dizcology added the owlbot:run Add this label to trigger the Owlbot post processor. label Nov 16, 2022
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Nov 16, 2022
@dizcology dizcology changed the title fix: snippetgen should call await on the operation coroutine before c… fix: snippetgen should call await on the operation coroutine before calling result Nov 16, 2022
@parthea parthea merged commit 69a49c6 into googleapis:main Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants