File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed
tests/system/large/functions Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change 19
19
import logging
20
20
import os
21
21
import random
22
+ import re
22
23
import shutil
23
24
import string
24
25
import tempfile
@@ -272,7 +273,10 @@ def provision_bq_managed_function(
272
273
# i.e. there are no references to variables or imports outside the
273
274
# body.
274
275
udf_code = textwrap .dedent (inspect .getsource (func ))
275
- udf_code = udf_code [udf_code .index ("def" ) :]
276
+ match = re .search (r"^def " , udf_code , flags = re .MULTILINE )
277
+ if match is None :
278
+ raise ValueError ("The UDF is not defined correctly." )
279
+ udf_code = udf_code [match .start () :]
276
280
277
281
with_connection_clause = (
278
282
(
Original file line number Diff line number Diff line change @@ -171,7 +171,12 @@ def featurize(x: int) -> list[float]:
171
171
def test_managed_function_series_apply (session , dataset_id , scalars_dfs ):
172
172
try :
173
173
174
- @session .udf (dataset = dataset_id , name = prefixer .create_prefix ())
174
+ # An explicit name with "def" in it is used to test the robustness of
175
+ # the user code extraction logic, which depends on that term.
176
+ bq_name = f"{ prefixer .create_prefix ()} _def_to_test_code_extraction"
177
+ assert "def" in bq_name , "The substring 'def' was not found in 'bq_name'"
178
+
179
+ @session .udf (dataset = dataset_id , name = bq_name )
175
180
def foo (x : int ) -> bytes :
176
181
return bytes (abs (x ))
177
182
You can’t perform that action at this time.
0 commit comments