Skip to content

Commit ec194ab

Browse files
Fix sandbox case
Signed-off-by: Devin Petersohn <devin.petersohn@snowflake.com>
1 parent 9e7f158 commit ec194ab

1 file changed

Lines changed: 50 additions & 32 deletions

File tree

src/snowflake/snowpark/functions.py

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,11 @@
229229
_to_col_if_str,
230230
_to_col_if_str_or_int,
231231
)
232-
from snowflake.snowpark.stored_procedure import StoredProcedure
232+
from snowflake.snowpark.context import _is_execution_environment_sandboxed_for_client
233+
from snowflake.snowpark.stored_procedure import (
234+
StoredProcedure,
235+
StoredProcedureRegistration,
236+
)
233237
from snowflake.snowpark.types import (
234238
ArrayType,
235239
DataType,
@@ -240,9 +244,9 @@
240244
TimestampTimeZone,
241245
TimestampType,
242246
)
243-
from snowflake.snowpark.udaf import UserDefinedAggregateFunction
244-
from snowflake.snowpark.udf import UserDefinedFunction
245-
from snowflake.snowpark.udtf import UserDefinedTableFunction
247+
from snowflake.snowpark.udaf import UDAFRegistration, UserDefinedAggregateFunction
248+
from snowflake.snowpark.udf import UDFRegistration, UserDefinedFunction
249+
from snowflake.snowpark.udtf import UDTFRegistration, UserDefinedTableFunction
246250

247251
# Python 3.8 needs to use typing.Iterable because collections.abc.Iterable is not subscriptable
248252
# Python 3.9 can use both
@@ -9460,13 +9464,16 @@ def udf(
94609464
)
94619465

94629466
if session is None:
9463-
warning(
9464-
name=f"udf_no_active_session_{func.__name__ if func else 'unknown'}",
9465-
text="WARN: UDF registration requires an active session. "
9466-
"This function was not registered.",
9467-
warning_times=1,
9468-
)
9469-
return func
9467+
udf_registration_method = UDFRegistration(session=session).register
9468+
if not _is_execution_environment_sandboxed_for_client:
9469+
# This happens when the user uses the decorator without an active session.
9470+
warning(
9471+
name=f"udf_no_active_session_{func.__name__ if func else 'unknown'}",
9472+
text="WARN: UDF registration requires an active session. "
9473+
"This function was not registered.",
9474+
warning_times=1,
9475+
)
9476+
return func
94709477
else:
94719478
udf_registration_method = session.udf.register
94729479

@@ -9716,13 +9723,16 @@ def udtf(
97169723
session
97179724
)
97189725
if session is None:
9719-
warning(
9720-
name=f"udtf_no_active_session_{handler.__name__ if handler else 'unknown'}",
9721-
text="WARN: UDTF registration requires an active session. "
9722-
"This function was not registered.",
9723-
warning_times=1,
9724-
)
9725-
return handler
9726+
udtf_registration_method = UDTFRegistration(session=session).register
9727+
if not _is_execution_environment_sandboxed_for_client:
9728+
# This happens when the user uses the decorator without an active session.
9729+
warning(
9730+
name=f"udtf_no_active_session_{handler.__name__ if handler else 'unknown'}",
9731+
text="WARN: UDTF registration requires an active session. "
9732+
"This function was not registered.",
9733+
warning_times=1,
9734+
)
9735+
return handler
97269736
else:
97279737
udtf_registration_method = session.udtf.register
97289738

@@ -9974,13 +9984,16 @@ def udaf(
99749984
session
99759985
)
99769986
if session is None:
9977-
warning(
9978-
name=f"udaf_no_active_session_{handler.__name__ if handler else 'unknown'}",
9979-
text="WARN: UDAF registration requires an active session. "
9980-
"This function was not registered.",
9981-
warning_times=1,
9982-
)
9983-
return handler
9987+
udaf_registration_method = UDAFRegistration(session=session).register
9988+
if not _is_execution_environment_sandboxed_for_client:
9989+
# This happens when the user uses the decorator without an active session.
9990+
warning(
9991+
name=f"udaf_no_active_session_{handler.__name__ if handler else 'unknown'}",
9992+
text="WARN: UDAF registration requires an active session. "
9993+
"This function was not registered.",
9994+
warning_times=1,
9995+
)
9996+
return handler
99849997
else:
99859998
udaf_registration_method = session.udaf.register
99869999

@@ -10676,13 +10689,18 @@ def sproc(
1067610689
session
1067710690
)
1067810691
if session is None:
10679-
warning(
10680-
name=f"sproc_no_active_session_{func.__name__ if func else 'unknown'}",
10681-
text="WARN: SPROC registration requires an active session. "
10682-
"This function was not registered.",
10683-
warning_times=1,
10684-
)
10685-
return func
10692+
sproc_registration_method = StoredProcedureRegistration(
10693+
session=session
10694+
).register
10695+
if not _is_execution_environment_sandboxed_for_client:
10696+
# This happens when the user uses the decorator without an active session.
10697+
warning(
10698+
name=f"sproc_no_active_session_{func.__name__ if func else 'unknown'}",
10699+
text="WARN: SPROC registration requires an active session. "
10700+
"This function was not registered.",
10701+
warning_times=1,
10702+
)
10703+
return func
1068610704
else:
1068710705
sproc_registration_method = session.sproc.register
1068810706

0 commit comments

Comments
 (0)