Skip to content

Commit cc11de5

Browse files
committed
fix for rare case where re-deploy exact same function object
1 parent 9a3170c commit cc11de5

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

bigframes/functions/remote_function.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,21 @@ def wrapper(func):
10421042
cloud_function_docker_repository,
10431043
)
10441044

1045+
# In the unlikely case where the user is trying to re-deploy the same
1046+
# function, cleanup the attributes we add below, first. This prevents
1047+
# the pickle from having dependencies that might not otherwise be
1048+
# present such as ibis or pandas.
1049+
def try_delattr(attr):
1050+
try:
1051+
delattr(func, attr)
1052+
except AttributeError:
1053+
pass
1054+
1055+
try_delattr("bigframes_cloud_function")
1056+
try_delattr("bigframes_remote_function")
1057+
try_delattr("output_dtype")
1058+
try_delattr("ibis_node")
1059+
10451060
rf_name, cf_name = remote_function_client.provision_bq_remote_function(
10461061
func,
10471062
ibis_signature.input_types,

tests/system/large/test_remote_function.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ def test_remote_function_stringify_with_ibis(
194194
def stringify(x):
195195
return f"I got {x}"
196196

197+
# Function should work locally.
198+
assert stringify(42) == "I got 42"
199+
197200
_, dataset_name, table_name = scalars_table_id.split(".")
198201
if not ibis_client.dataset:
199202
ibis_client.dataset = dataset_name
@@ -205,7 +208,7 @@ def stringify(x):
205208
pandas_df_orig = bigquery_client.query(sql).to_dataframe()
206209

207210
col = table[col_name]
208-
col_2x = stringify(col).name("int64_str_col")
211+
col_2x = stringify.ibis_node(col).name("int64_str_col")
209212
table = table.mutate([col_2x])
210213
sql = table.compile()
211214
pandas_df_new = bigquery_client.query(sql).to_dataframe()

0 commit comments

Comments
 (0)