gapic-generator-python icon indicating copy to clipboard operation
gapic-generator-python copied to clipboard

Missing asyncio.run in sample code for async clients.

Open ohmayr opened this issue 2 years ago • 0 comments

The generated sample code for async clients is missing asyncio.run which results in the sample code to not work as expected.

As an example, working sample code for accessapproval_v1_generated_access_approval_list_approval_requests_async.py should look like:

from google.cloud import accessapproval_v1
import asyncio
import logging


PYTHONWARNINGS="default"

try:
    import http.client as http_client
except ImportError:
    # Python 2
    import httplib as http_client
http_client.HTTPConnection.debuglevel = 1

# You must initialize logging, otherwise you'll not see debug output.
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
async def sample_list_approval_requests():
    # Create a client
    client = accessapproval_v1.AccessApprovalAsyncClient(transport="rest")

    # Initialize request argument(s)
    request = accessapproval_v1.ListApprovalRequestsMessage(
        parent="projects/someproject"
    )

    # Make the request
    page_result = await client.list_approval_requests(request=request)

    # Handle the response
    async for response in page_result:
        print(response)

# [END accessapproval_v1_generated_AccessApproval_ListApprovalRequests_async]

asyncio.run(sample_list_approval_requests())

Need to update the generator code to reflect the above changes in the generated sample.

ohmayr avatar Oct 11 '23 17:10 ohmayr