Skip to content

SNOW-2081762: Handle no session during Sproc, UDxF registration #3331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sfc-gh-heshah
Copy link
Collaborator

@sfc-gh-heshah sfc-gh-heshah commented May 5, 2025

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

    Fixes SNOW-2081762

  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.

    Allow Sproc/UDxF creation/registration without a live session. An active session is assumed to be required at the call site of the resultant Sproc/UDxF.

@github-actions github-actions bot added the local testing Local Testing issues/PRs label May 5, 2025
@sfc-gh-snowflakedb-snyk-sa
Copy link

sfc-gh-snowflakedb-snyk-sa commented May 5, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

Copy link
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@sfc-gh-heshah sfc-gh-heshah marked this pull request as ready for review May 5, 2025 22:37
@sfc-gh-heshah sfc-gh-heshah requested review from a team as code owners May 5, 2025 22:37
@sfc-gh-heshah sfc-gh-heshah added NO-PANDAS-CHANGEDOC-UPDATES This PR does not update Snowpark pandas docs NO-CHANGELOG-UPDATES This pull request does not need to update CHANGELOG.md snowpark-ast Change materially affects the Snowpark AST labels May 5, 2025 — with Graphite App
@sfc-gh-heshah sfc-gh-heshah removed the snowpark-ast Change materially affects the Snowpark AST label May 5, 2025
@sfc-gh-heshah sfc-gh-heshah added the snowpark-server Server-side snowpark work label May 5, 2025 — with Graphite App
Comment on lines +857 to +854
if self._session is not None:
stmt = self._session._ast_batch.bind()
ast = with_src_position(stmt.expr.stored_procedure, stmt)
ast_id = stmt.uid
else:
ast = proto.StoredProcedure()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is information being lost when the session is not initialized?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The source information from where session.{sproc,udaf,udf,udtf}.register is called will be lost.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we still capture the source information when session is None? source read only depends on reading python call stack and frames right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually we will be able to once Snowpark object own their AST statements, but for now because Bind statements can only be created in association with a Session instance that owns an AstBatch instance, we will lose the call stack and frames from this point in the code.

@sfc-gh-heshah sfc-gh-heshah force-pushed the heshah-SNOW-2081762-Handle-no-session-during-Sproc-UDxF-registration branch 2 times, most recently from 23c8d05 to 8dc25ec Compare May 7, 2025 19:49
Comment on lines +117 to +120
session = (
self._session or snowflake.snowpark.session._get_active_session()
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible session is still None here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, if you try to call a UDxF without an active session, it means it will not have been registered in the first place.

This is likely moving the eventual failure slightly earlier in the pipeline, where if the session is still None here, _get_active_session() will raise an error.

@@ -87,6 +88,7 @@ def __init__(
packages: Optional[List[Union[str, ModuleType]]] = None,
_ast: Optional[proto.Udf] = None,
_ast_id: Optional[int] = None,
_session: Optional["snowflake.snowpark.session.Session"] = None,
Copy link
Contributor

@sfc-gh-aling sfc-gh-aling May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may overlook but I didn't see any caller passing the _session parameter?
when is this parameter used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for catching this! Missed passing in the _session parameter at the call sites in UDFRegistration methods in this file.

@sfc-gh-heshah sfc-gh-heshah force-pushed the heshah-SNOW-2081762-Handle-no-session-during-Sproc-UDxF-registration branch from 8dc25ec to 453ef2f Compare May 7, 2025 21:43
@sfc-gh-heshah sfc-gh-heshah force-pushed the heshah-SNOW-2081762-Handle-no-session-during-Sproc-UDxF-registration branch 2 times, most recently from 69506f3 to 0083cef Compare May 15, 2025 21:44
@sfc-gh-heshah sfc-gh-heshah force-pushed the heshah-SNOW-2081762-Handle-no-session-during-Sproc-UDxF-registration branch from 0083cef to 8e02221 Compare May 16, 2025 22:34
@sfc-gh-heshah sfc-gh-heshah force-pushed the heshah-SNOW-2081762-Handle-no-session-during-Sproc-UDxF-registration branch from 8e02221 to f30c9bc Compare June 5, 2025 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
local testing Local Testing issues/PRs NO-CHANGELOG-UPDATES This pull request does not need to update CHANGELOG.md NO-PANDAS-CHANGEDOC-UPDATES This PR does not update Snowpark pandas docs snowpark-server Server-side snowpark work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants