Skip to content

SNOW-4174500: Fix nested udxf inheriting inaccessable stage path - #4412

Merged
sfc-gh-mayliu merged 4 commits into
mainfrom
SNOW-4174500-rewrite-stage-imports-fix
Oct 5, 2026
Merged

sfc-gh-mayliu merged 4 commits into
mainfrom
SNOW-4174500-rewrite-stage-imports-fix

Conversation

@sfc-gh-mayliu

@sfc-gh-mayliu sfc-gh-mayliu commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator
  1. Which Jira issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    Fixes SNOW-4174500

  2. Fill out the following pre-review checklist:

    • I am adding a new automated test(s) to verify correctness of my new code
      • If this test skips Local Testing mode, I'm requesting review from @snowflakedb/local-testing
    • I am adding new logging messages
    • I am adding a new telemetry message
    • I am adding new credentials
    • I am adding a new dependency
    • If this is a new feature/behavior, I'm adding the Local Testing parity changes.
    • I acknowledge that I have ensured my changes to be thread-safe. Follow the link for more information: Thread-safe Developer Guidelines
    • If adding any arguments to public Snowpark APIs or creating new public Snowpark APIs, I acknowledge that I have ensured my changes include AST support. Follow the link for more information: AST Support Guidelines
  3. Please describe how your code solves the related issue.

    Please write a short description of how your code change solves the related issue.

Bug

When a stored procedure declares IMPORTS, Snowflake resolves those to absolute app-package stage paths and seeds them into session._import_paths. Any nested UDxF registered inside that procedure with no explicit imports= argument inherits those paths verbatim into its DDL, i.e:

CREATE TEMPORARY FUNCTION snowpark_temp_udtf_xyz
  IMPORTS = ('@APP_PKG."APP_ARTIFACTS_V1.0".APP_FILES/pandas_helper.py')

The executing role can't access that pandas_helper.py path on stage, so Snowflake rejects the DDL. This affects apply_in_pandas, session.udf.register, session.udtf.register, and any other UDxF registration that omits imports=.

Fix

Inside a stored procedure, the platform already extracts every staged import to a local temp directory (sys._xoptions["snowflake_import_directory"]).
https://docs.snowflake.com/en/developer-guide/udf/python/udf-python-examples#reading-a-statically-specified-file-using-imports

The fix looks for each stage path's file there and re-uploads it to the session's own temp stage, so that the executing role always owns the redirected path and replaces the inaccessible original path. No behavioral change outside a stored procedure since this fix targets nested UDxF calls. Can be disabled via session.conf.set("restage_stored_procedure_imports", False)

@codecov-commenter

codecov-commenter commented Oct 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.83333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.46%. Comparing base (03a1ba4) to head (2c64e1d).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/snowflake/snowpark/session.py 95.83% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4412      +/-   ##
==========================================
- Coverage   95.47%   95.46%   -0.01%     
==========================================
  Files         176      176              
  Lines       45271    45295      +24     
  Branches     7759     7766       +7     
==========================================
+ Hits        43222    43243      +21     
- Misses       1269     1270       +1     
- Partials      780      782       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sfc-gh-mayliu
sfc-gh-mayliu requested a review from a team October 5, 2026 22:58
@sfc-gh-mayliu
sfc-gh-mayliu enabled auto-merge (squash) October 5, 2026 22:59
@sfc-gh-mayliu
sfc-gh-mayliu merged commit afac69d into main Oct 5, 2026
29 of 31 checks passed
@sfc-gh-mayliu
sfc-gh-mayliu deleted the SNOW-4174500-rewrite-stage-imports-fix branch October 5, 2026 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants