diff --git a/bigframes/functions/_function_client.py b/bigframes/functions/_function_client.py index ae19dc1480..d98633e1cc 100644 --- a/bigframes/functions/_function_client.py +++ b/bigframes/functions/_function_client.py @@ -366,8 +366,8 @@ def generate_cloud_function_code( def create_cloud_function( self, def_, - cf_name, *, + random_name, input_types: Tuple[str], output_type: str, package_requirements=None, @@ -428,9 +428,9 @@ def create_cloud_function( create_function_request.parent = ( self.get_cloud_function_fully_qualified_parent() ) - create_function_request.function_id = cf_name + create_function_request.function_id = random_name function = functions_v2.Function() - function.name = self.get_cloud_function_fully_qualified_name(cf_name) + function.name = self.get_cloud_function_fully_qualified_name(random_name) function.build_config = functions_v2.BuildConfig() function.build_config.runtime = python_version function.build_config.entry_point = entry_point @@ -497,24 +497,25 @@ def create_cloud_function( # Cleanup os.remove(archive_path) except google.api_core.exceptions.AlreadyExists: - # If a cloud function with the same name already exists, let's - # update it - update_function_request = functions_v2.UpdateFunctionRequest() - update_function_request.function = function - operation = self._cloud_functions_client.update_function( - request=update_function_request - ) - operation.result() + # b/437124912: The most likely scenario is that + # `create_function` had a retry due to a network issue. The + # retried request then fails because the first call actually + # succeeded, but we didn't get the successful response back. + # + # Since the function name was randomly chosen to avoid + # conflicts, we know the AlreadyExist can only happen because + # we created it. This error is safe to ignore. + pass # Fetch the endpoint of the just created function - endpoint = self.get_cloud_function_endpoint(cf_name) + endpoint = self.get_cloud_function_endpoint(random_name) if not endpoint: raise bf_formatting.create_exception_with_feedback_link( ValueError, "Couldn't fetch the http endpoint." ) logger.info( - f"Successfully created cloud function {cf_name} with uri ({endpoint})" + f"Successfully created cloud function {random_name} with uri ({endpoint})" ) return endpoint @@ -571,7 +572,7 @@ def provision_bq_remote_function( if not cf_endpoint: cf_endpoint = self.create_cloud_function( def_, - cloud_function_name, + random_name=cloud_function_name, input_types=input_types, output_type=output_type, package_requirements=package_requirements,