gemini-code-assist[bot] commented on code in PR #38847:
URL: https://github.com/apache/beam/pull/38847#discussion_r3374572714


##########
sdks/python/apache_beam/runners/dataflow/internal/apiclient.py:
##########
@@ -519,11 +519,12 @@ def __init__(self, options, root_staging_location=None):
     client_options = None
     transport = None
     if self.google_cloud_options.dataflow_endpoint:
-      endpoint = self.google_cloud_options.dataflow_endpoint
+      endpoint = self.google_cloud_options.dataflow_endpoint.strip()
       if 'localhost' in endpoint or 'sandbox' in endpoint:
         transport = 'rest'
       else:
         endpoint = re.sub('^https?://', '', endpoint)
+      endpoint = endpoint.rstrip('/')
       client_options = client_options_lib.ClientOptions(api_endpoint=endpoint)

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   If `self.google_cloud_options.dataflow_endpoint` consists only of whitespace 
characters, calling `.strip()` will result in an empty string `""`. This empty 
string is then passed to `ClientOptions(api_endpoint="")`, which could lead to 
unexpected behavior or failures later. It is safer to verify that the endpoint 
is not empty after stripping before proceeding.
   
   ```suggestion
       if self.google_cloud_options.dataflow_endpoint:
         endpoint = self.google_cloud_options.dataflow_endpoint.strip()
         if endpoint:
           if 'localhost' in endpoint or 'sandbox' in endpoint:
             transport = 'rest'
           else:
             endpoint = re.sub('^https?://', '', endpoint)
           endpoint = endpoint.rstrip('/')
           client_options = 
client_options_lib.ClientOptions(api_endpoint=endpoint)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to