Skip to content

Patching certain functions raises NameError: name 'snowflake' is not defined #4120

@narciero

Description

@narciero

Please answer these questions before submitting your issue. Thanks!

  1. What version of Python are you using?

    Python 3.12.11

  2. What operating system and processor architecture are you using?

    macOS-26.2-arm64-arm-64bit

  3. What are the component versions in the environment (pip freeze)?

    snowflake-connector-python==4.3.0
    snowflake-ml-python==1.29.0
    snowflake-snowpark-python==1.47.0
    
  4. What did you do?

    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")
    
    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
  5. 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
    
  6. 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.

Metadata

Metadata

Assignees

Labels

status-triage_doneInitial triage done, will be further handled by the driver team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions