You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SNOW-3257435: Patching certain functions raises NameError: name 'snowflake' is not defined #4120
fromsnowflake.snowparkimportSessionfromsnowflake.snowpark.functionsimportcol, squarefromsnowflake.snowpark.mockimportpatch@patch(square)defmock_square(x):
raiseAssertionError("never reached")
session=Session.builder.config("local_testing", True).getOrCreate()
df=session.create_dataframe([[1]], schema=["x"])
df.select(square(col("x"))).collect() # NameError: name 'snowflake' is not defined
What did you expect to see?
The patch function (mock_square) should be executed. Instead, the following error is thrown:
NameError: name 'snowflake' is not defined
Can you set logging to DEBUG and collect the logs?
N/A
Suspected Issue
The ColumnOrName = Union["snowflake.snowpark.column.Column", str] typedef in _internal/type_utils.py
uses a forward ref.
When handle_function_expression calls typing.get_type_hints() on the
original function being patched, it evaluates the forward ref in _functions/scalar_functions.py's globals
where 'snowflake' is not a bare name.
changed the title [-]Patching certain functions raises "NameError: name 'snowflake' is not defined"[/-][+]Patching certain functions raises `NameError: name 'snowflake' is not defined`[/+]on Mar 13, 2026
Thanks for raising the issue.
I checked the code snippet and able to reproduce. Its actually working as expected.
With regular session: The output is [Row(SQUARE("X")=1.0)]
With local testing: The output is SnowparkLocalTestingException: Error executing mocked function 'square'. See error traceback for detailed information.
You are getting an error with local_testing because you are throwing an exception raise AssertionError("never reached")
Local Session (Expected Failure): The Local Testing framework use the @patch. Your function then does exactly what you told it to do: it crashes with an AssertionError. Whereas for a regular session, it ignores the @patch, and it uses the regular built-in square function.
So if you want you mock_square function same as a regular session, you can use the code below instead of throwing an error
from snowflake.snowpark import Session
from snowflake.snowpark.functions import col, square
from snowflake.snowpark.mock import patch
@patch(square)
def mock_square(x):
#raise AssertionError("never reached")
return x * x
session = Session.builder.config('local_testing', True).create()
df = session.create_dataframe([[1]], schema=["x"])
df.select(square(col("x"))).collect() # NameError: name 'snowflake' is not defined
Output:
[Row(SQUARE("X")=1.0)]
changed the title [-]Patching certain functions raises `NameError: name 'snowflake' is not defined`[/-][+]SNOW-3257435: Patching certain functions raises `NameError: name 'snowflake' is not defined`[/+]on Mar 19, 2026
Activity
[-]Patching certain functions raises "NameError: name 'snowflake' is not defined"[/-][+]Patching certain functions raises `NameError: name 'snowflake' is not defined`[/+]sfc-gh-sghosh commentedon Mar 17, 2026
Hello @narciero ,
Thanks for raising the issue.
I checked the code snippet and able to reproduce. Its actually working as expected.
With regular session: The output is [Row(SQUARE("X")=1.0)]
With local testing: The output is SnowparkLocalTestingException: Error executing mocked function 'square'. See error traceback for detailed information.
You are getting an error with local_testing because you are throwing an exception raise AssertionError("never reached")
Local Session (Expected Failure): The Local Testing framework use the @patch. Your function then does exactly what you told it to do: it crashes with an AssertionError. Whereas for a regular session, it ignores the @patch, and it uses the regular built-in square function.
So if you want you mock_square function same as a regular session, you can use the code below instead of throwing an error
[-]Patching certain functions raises `NameError: name 'snowflake' is not defined`[/-][+]SNOW-3257435: Patching certain functions raises `NameError: name 'snowflake' is not defined`[/+]