pythonstored-proceduressnowflake-cloud-data-platform

How do I resolve SnowparkSQLException: ... User is empty in function for Snowpark python SPROC invocation?


When invoking a Snowpark-registered SPROC, I get the following error:

SnowparkSQLException: (1304): <uuid>: 100357 (P0000): <uuid>: Python Interpreter Error:
snowflake.connector.errors.ProgrammingError: 251005: User is empty in function MY_FUNCTION with handler compute

for the following python code and invocation:

def my_function(session: Session,
                input_table: str,
                limit: int) -> None:
    # Even doing nothing doesn't work!
    return

sproc_my_function = my_session.sproc.register(func=my_function,
                                           name='my_function',
                                           is_permanent=True,
                                           replace=True,
                                           stage_location='@STAGE_LOC',
                                           execute_as="owner",


input_table = 'x.y.MY_INPUT_TABLE'

sproc_process_row(my_session,
                  input_table,
                  100,
                  )

I can't find a reference to this exception and "User is empty in function" anywhere on the internet - which makes me wonder if its a drop-through of some sort. I also can't find a way to pass a user to the register method (this is already done successfully when my_session is set up).

Please help!


Solution

  • Using Snowflake Notebooks:

    from snowflake.snowpark.session import Session
    my_session = snowflake.snowpark.context.get_active_session()
    
    def my_function(session: Session,
                    input_table: str,
                    limit: int) -> None:
        return None
    
    sproc_my_function = my_session.sproc.register(func=my_function,
                                               name='my_function',
                                               is_permanent=True,
                                               replace=True,
                                               stage_location='STAGE_LOC',
                                               execute_as="owner",
                                               packages=["snowflake-snowpark-python"])
    

    Output:

    enter image description here