Skip to content

Commit cd954ac

Browse files
authored
fix: make remote_function more robust when there are create_function retries (#1973)
1 parent 41dda88 commit cd954ac

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

bigframes/functions/_function_client.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,8 @@ def generate_cloud_function_code(
366366
def create_cloud_function(
367367
self,
368368
def_,
369-
cf_name,
370369
*,
370+
random_name,
371371
input_types: Tuple[str],
372372
output_type: str,
373373
package_requirements=None,
@@ -428,9 +428,9 @@ def create_cloud_function(
428428
create_function_request.parent = (
429429
self.get_cloud_function_fully_qualified_parent()
430430
)
431-
create_function_request.function_id = cf_name
431+
create_function_request.function_id = random_name
432432
function = functions_v2.Function()
433-
function.name = self.get_cloud_function_fully_qualified_name(cf_name)
433+
function.name = self.get_cloud_function_fully_qualified_name(random_name)
434434
function.build_config = functions_v2.BuildConfig()
435435
function.build_config.runtime = python_version
436436
function.build_config.entry_point = entry_point
@@ -497,24 +497,25 @@ def create_cloud_function(
497497
# Cleanup
498498
os.remove(archive_path)
499499
except google.api_core.exceptions.AlreadyExists:
500-
# If a cloud function with the same name already exists, let's
501-
# update it
502-
update_function_request = functions_v2.UpdateFunctionRequest()
503-
update_function_request.function = function
504-
operation = self._cloud_functions_client.update_function(
505-
request=update_function_request
506-
)
507-
operation.result()
500+
# b/437124912: The most likely scenario is that
501+
# `create_function` had a retry due to a network issue. The
502+
# retried request then fails because the first call actually
503+
# succeeded, but we didn't get the successful response back.
504+
#
505+
# Since the function name was randomly chosen to avoid
506+
# conflicts, we know the AlreadyExist can only happen because
507+
# we created it. This error is safe to ignore.
508+
pass
508509

509510
# Fetch the endpoint of the just created function
510-
endpoint = self.get_cloud_function_endpoint(cf_name)
511+
endpoint = self.get_cloud_function_endpoint(random_name)
511512
if not endpoint:
512513
raise bf_formatting.create_exception_with_feedback_link(
513514
ValueError, "Couldn't fetch the http endpoint."
514515
)
515516

516517
logger.info(
517-
f"Successfully created cloud function {cf_name} with uri ({endpoint})"
518+
f"Successfully created cloud function {random_name} with uri ({endpoint})"
518519
)
519520
return endpoint
520521

@@ -571,7 +572,7 @@ def provision_bq_remote_function(
571572
if not cf_endpoint:
572573
cf_endpoint = self.create_cloud_function(
573574
def_,
574-
cloud_function_name,
575+
random_name=cloud_function_name,
575576
input_types=input_types,
576577
output_type=output_type,
577578
package_requirements=package_requirements,

0 commit comments

Comments
 (0)