Skip to content

fix(retail): add region tag for Python - Update rejoin user events #13498

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
4 changes: 4 additions & 0 deletions retail/interactive-tutorials/events/rejoin_user_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

# Starts a user event rejoin operation using Retail API.
#
# [START retail_rejoin_user_events]

import google.auth
from google.cloud.retail import RejoinUserEventsRequest, UserEventServiceClient

Expand Down Expand Up @@ -54,3 +56,5 @@ def call_rejoin_user_events():
write_user_event(visitor_id)
call_rejoin_user_events()
purge_user_event(visitor_id)

# [END retail_rejoin_user_events]
Comment on lines 56 to +60
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To improve the maintainability and reusability of this script, it's a Python best practice to place executable code inside an if __name__ == '__main__': block. This prevents the script's main logic from running automatically when its contents are imported into other modules, making the code more robust and easier to test programmatically without relying on a subprocess. Since this file is now being designated as a sample with region tags, adhering to this convention is particularly important.

Suggested change
write_user_event(visitor_id)
call_rejoin_user_events()
purge_user_event(visitor_id)
# [END retail_rejoin_user_events]
if __name__ == "__main__":
write_user_event(visitor_id)
call_rejoin_user_events()
purge_user_event(visitor_id)
# [END retail_rejoin_user_events]