Skip to content

Commit 499e00a

Browse files
authored
chore: ensure udfs are actively deleted, make pre-commit mypy dep consistent (#1522)
1 parent ab2455f commit 499e00a

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ repos:
3838
rev: v1.10.0
3939
hooks:
4040
- id: mypy
41-
additional_dependencies: [types-requests, types-tabulate, pandas-stubs]
41+
additional_dependencies: [types-requests, types-tabulate, pandas-stubs<=2.2.3.241126]
4242
exclude: "^third_party"
4343
args: ["--check-untyped-defs", "--explicit-package-bases", "--ignore-missing-imports"]

tests/system/large/functions/test_managed_function.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def multiply(x, y):
7272
)
7373
finally:
7474
# clean up the gcp assets created for the managed function.
75-
cleanup_function_assets(multiply, bigquery_client)
75+
cleanup_function_assets(multiply, bigquery_client, ignore_failures=False)
7676

7777

7878
def test_managed_function_stringify_with_ibis(
@@ -118,7 +118,7 @@ def stringify(x):
118118
)
119119
finally:
120120
# clean up the gcp assets created for the managed function.
121-
cleanup_function_assets(stringify, bigquery_client)
121+
cleanup_function_assets(stringify, bigquery_client, ignore_failures=False)
122122

123123

124124
@pytest.mark.parametrize(
@@ -167,7 +167,7 @@ def featurize(x: int) -> list[array_dtype]: # type: ignore
167167

168168
finally:
169169
# Clean up the gcp assets created for the managed function.
170-
cleanup_function_assets(featurize, session.bqclient)
170+
cleanup_function_assets(featurize, session.bqclient, ignore_failures=False)
171171

172172

173173
@pytest.mark.parametrize(
@@ -234,7 +234,7 @@ def foo(x: int) -> typ: # type:ignore
234234
pandas.testing.assert_frame_equal(bf_result_gbq, pd_result, check_dtype=False)
235235
finally:
236236
# Clean up the gcp assets created for the managed function.
237-
cleanup_function_assets(foo, session.bqclient)
237+
cleanup_function_assets(foo, session.bqclient, ignore_failures=False)
238238

239239

240240
@pytest.mark.parametrize(
@@ -274,7 +274,7 @@ def foo_list(x: int) -> list[typ]: # type:ignore
274274
pandas.testing.assert_frame_equal(bf_result, pd_result, check_dtype=False)
275275
finally:
276276
# Clean up the gcp assets created for the managed function.
277-
cleanup_function_assets(foo_list, session.bqclient)
277+
cleanup_function_assets(foo_list, session.bqclient, ignore_failures=False)
278278

279279

280280
def test_managed_function_series_combine(session, scalars_dfs):
@@ -330,7 +330,9 @@ def add(x: int, y: int) -> int:
330330
pandas.testing.assert_series_equal(bf_result, pd_result, check_dtype=False)
331331
finally:
332332
# Clean up the gcp assets created for the managed function.
333-
cleanup_function_assets(add_managed_func, session.bqclient)
333+
cleanup_function_assets(
334+
add_managed_func, session.bqclient, ignore_failures=False
335+
)
334336

335337

336338
def test_managed_function_series_combine_array_output(session, scalars_dfs):
@@ -391,7 +393,9 @@ def add_list(x: int, y: int) -> list[int]:
391393
pandas.testing.assert_series_equal(bf_result_gbq, pd_result, check_dtype=False)
392394
finally:
393395
# Clean up the gcp assets created for the managed function.
394-
cleanup_function_assets(add_list_managed_func, session.bqclient)
396+
cleanup_function_assets(
397+
add_list_managed_func, session.bqclient, ignore_failures=False
398+
)
395399

396400

397401
def test_managed_function_dataframe_map(session, scalars_dfs):
@@ -425,7 +429,7 @@ def add_one(x):
425429
pandas.testing.assert_frame_equal(bf_result, pd_result)
426430
finally:
427431
# Clean up the gcp assets created for the managed function.
428-
cleanup_function_assets(mf_add_one, session.bqclient)
432+
cleanup_function_assets(mf_add_one, session.bqclient, ignore_failures=False)
429433

430434

431435
def test_managed_function_dataframe_map_array_output(
@@ -464,7 +468,9 @@ def add_one_list(x):
464468
pandas.testing.assert_frame_equal(bf_result_gbq, pd_result, check_dtype=False)
465469
finally:
466470
# Clean up the gcp assets created for the managed function.
467-
cleanup_function_assets(mf_add_one_list, session.bqclient)
471+
cleanup_function_assets(
472+
mf_add_one_list, session.bqclient, ignore_failures=False
473+
)
468474

469475

470476
def test_managed_function_dataframe_apply_axis_1(session, scalars_dfs):
@@ -500,7 +506,7 @@ def add_ints(x, y):
500506
)
501507
finally:
502508
# Clean up the gcp assets created for the managed function.
503-
cleanup_function_assets(add_ints_mf, session.bqclient)
509+
cleanup_function_assets(add_ints_mf, session.bqclient, ignore_failures=False)
504510

505511

506512
def test_managed_function_dataframe_apply_axis_1_array_output(session):
@@ -605,4 +611,4 @@ def foo(x, y, z):
605611

606612
finally:
607613
# Clean up the gcp assets created for the managed function.
608-
cleanup_function_assets(foo, session.bqclient)
614+
cleanup_function_assets(foo, session.bqclient, ignore_failures=False)

tests/system/utils.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -401,14 +401,20 @@ def cleanup_function_assets(
401401
) -> None:
402402
"""Clean up the GCP assets behind a bigframess function."""
403403

404-
# Clean up bigframes function.
404+
# Clean up bigframes bigquery function.
405405
try:
406406
bigquery_client.delete_routine(bigframes_func.bigframes_bigquery_function)
407407
except Exception:
408408
# By default don't raise exception in cleanup.
409409
if not ignore_failures:
410410
raise
411411

412+
if not ignore_failures:
413+
# Make sure that the BQ routins is actually deleted
414+
with pytest.raises(google.api_core.exceptions.NotFound):
415+
bigquery_client.get_routine(bigframes_func.bigframes_bigquery_function)
416+
417+
# Clean up bigframes cloud run function
412418
if cloudfunctions_client:
413419
# Clean up cloud function
414420
try:
@@ -420,6 +426,16 @@ def cleanup_function_assets(
420426
if not ignore_failures:
421427
raise
422428

429+
if not ignore_failures:
430+
# Make sure the cloud run function is actually deleted
431+
try:
432+
gcf = cloudfunctions_client.get_function(
433+
name=bigframes_func.bigframes_cloud_function
434+
)
435+
assert gcf.state is functions_v2.Function.State.DELETING
436+
except google.cloud.exceptions.NotFound:
437+
pass
438+
423439

424440
def get_function_name(func, package_requirements=None, is_row_processor=False):
425441
"""Get a bigframes function name for testing given a udf."""

0 commit comments

Comments
 (0)