Skip to content

fix(retail): add region tag for Python - Update remove fulfillment places #13466

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

# Remove place IDs using Retail API.
#
# [START retail_remove_fulfillment_places]
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The added region tag exposes the enclosed code as a public sample. The code within this new region tag has a few issues that should be addressed:

  1. The remove_places function is defined as async, but it doesn't use await for any asynchronous operations. The polling loop uses time.sleep(), which is synchronous and blocks the event loop. This function can be a regular synchronous function.

  2. The try...except GoogleAPICallError: pass block (lines 62-68) silently ignores potential failures from the remove_fulfillment_places operation. This can lead to subsequent steps running on an incorrect state and makes debugging very difficult. The operation's result should be properly checked for errors. The comment on line 61 is also misleading.

  3. The remove_places function also calls get_product and delete_product, which are teardown steps. This is a side effect that is not clear from the function name.

#
import asyncio
import random
import string
Expand Down Expand Up @@ -72,3 +74,5 @@ async def remove_places(product_name: str):
product = create_product(product_id)

asyncio.run(remove_places(product.name))

# [END retail_remove_fulfillment_places]