Skip to content

SNOW-2438654: Can't write to system$reference('table', ...) passed in to Snowpark Python #3915

@jacob-tolar-bridg

Description

@jacob-tolar-bridg
  1. What version of Python are you using?

    3.13 (Running snowpark-python via Snowflake Python stored procedure)

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

    Snowflake hosted (see above) within a stored procedure

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

   snowflake-snowpark-python==1.40.0 
   pandas==2.3.1
  1. What did you do?
create or replace temp table system_reference_test(table_name varchar, comment varchar);

WITH test_procedure_system_reference AS PROCEDURE ( table_name string )
  RETURNS varchar
  LANGUAGE PYTHON
  RUNTIME_VERSION = 3.13
  PACKAGES = ('snowflake-snowpark-python==1.40.0','pandas==2.3.1')
  HANDLER = 'main' 
  AS
  $$
from snowflake.snowpark import Session

def validate_object_name(*args, **kwargs):
    return True

def main(session: Session, table_name: str):
    try:
        df = session.sql("select ?, 'fails to insert'", params=[table_name])
        # This fails
        df.write.insertInto(table_name)
    except:
        pass

    # This works
    session._table_exists = validate_object_name
    df = session.sql("select ?, 'success'", params=[table_name])
    df.write.insertInto(table_name)

    return table_name
  $$
  call test_procedure_system_reference(SYSTEM$REFERENCE('TABLE', 'system_reference_test', 'CALL', 'INSERT', 'TRUNCATE'));

-- This shows one row, for 'success'
-- The first row fails because _table_exists returns false
-- see https://github.com/snowflakedb/snowpark-python/blob/main/src/snowflake/snowpark/dataframe_writer.py#L1085-L1091
select * from system_reference_test;
  1. What did you expect to see?

I expect to be able to use SYSTEM$REFERENCE with Python stored procedures using Snowpark Python (this works as expected for stored procedures written in Snowflake SQL), i.e. insertInto should write into a referenced table successfully.

  1. Can you set logging to DEBUG and collect the logs?

I think the snippet above is sufficient to demonstrate the issue, if not let me know and I can provide further input.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds triageInitial RCA is required

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions