Skip to content

Commit 6b8df76

Browse files
authored
SNOW-1418523: Minor refactor for resolve_imports_and_packages (#2311)
1 parent 5616802 commit 6b8df76

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

src/snowflake/snowpark/_internal/udf_utils.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,7 @@ def resolve_imports_and_packages(
10731073
)
10741074
)
10751075

1076+
all_urls = []
10761077
if session is not None:
10771078
import_only_stage = (
10781079
unwrap_stage_location_single_quote(stage_location)
@@ -1086,7 +1087,6 @@ def resolve_imports_and_packages(
10861087
else session.get_session_stage(statement_params=statement_params)
10871088
)
10881089

1089-
if session:
10901090
if imports:
10911091
udf_level_imports = {}
10921092
for udf_import in imports:
@@ -1114,22 +1114,15 @@ def resolve_imports_and_packages(
11141114
upload_and_import_stage,
11151115
statement_params=statement_params,
11161116
)
1117-
else:
1118-
all_urls = []
1119-
else:
1120-
all_urls = []
11211117

11221118
dest_prefix = get_udf_upload_prefix(udf_name)
11231119

11241120
# Upload closure to stage if it is beyond inline closure size limit
11251121
handler = inline_code = upload_file_stage_location = None
1126-
custom_python_runtime_version_allowed = False
1122+
# As cloudpickle is being used, we cannot allow a custom runtime
1123+
custom_python_runtime_version_allowed = not isinstance(func, Callable)
11271124
if session is not None:
11281125
if isinstance(func, Callable):
1129-
custom_python_runtime_version_allowed = (
1130-
False # As cloudpickle is being used, we cannot allow a custom runtime
1131-
)
1132-
11331126
# generate a random name for udf py file
11341127
# and we compress it first then upload it
11351128
udf_file_name_base = f"udf_py_{random_number()}"
@@ -1199,11 +1192,6 @@ def resolve_imports_and_packages(
11991192
skip_upload_on_content_match=skip_upload_on_content_match,
12001193
)
12011194
all_urls.append(upload_file_stage_location)
1202-
else:
1203-
if isinstance(func, Callable):
1204-
custom_python_runtime_version_allowed = False
1205-
else:
1206-
custom_python_runtime_version_allowed = True
12071195

12081196
# build imports and packages string
12091197
all_imports = ",".join(

0 commit comments

Comments
 (0)