Skip to content
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

SNOW-1062439: Automatically closing sessions and connections using Python with leads to errors when deploying to stored procedures #1259

Closed
zaramzamzam opened this issue Feb 20, 2024 · 3 comments · Fixed by #1263
Labels
feature New feature or request

Comments

@zaramzamzam
Copy link
Contributor

When creating a session I am using the Python with statement in order to automatically close the connection and remove the session.

What is the current behavior?

Currently using the with statement to automatically close connections when running in Stored Procedures or Snowflake Streamlit apps throws an error due to closing the connection not being allowed in stored procedures.

def close(self) -> None:
"""Close this session."""
if is_in_stored_procedure():
raise SnowparkClientExceptionMessages.DONT_CLOSE_SESSION_IN_SP()

This leads to the code having to be different when running locally or in stored procedures.

What is the desired behavior?

Ideally I would like the same Python code to run locally as well as in stored procedures or Streamlit apps.

How would this improve snowflake-snowpark-python?

This would make it easier to develop locally and then moving deployments to Snowflake, for example in the form of Streamlit Apps.

Possible Solution

Instead of throwing an error a warning could be logged and when detecting that code is running inside a stored procedure the session is not closed, ignoring the with functionality.

@zaramzamzam zaramzamzam added the feature New feature or request label Feb 20, 2024
@github-actions github-actions bot changed the title Automatically closing sessions and connections using Python with leads to errors when deploying to stored procedures SNOW-1062439: Automatically closing sessions and connections using Python with leads to errors when deploying to stored procedures Feb 20, 2024
@zaramzamzam
Copy link
Contributor Author

If this is seen as an improvement I would be happy to contribute to this issue via a PR.

@sfc-gh-stan
Copy link
Collaborator

Thanks for opening this. The proposed change makes sense to me, please open a PR and request review from @sfc-gh-yixie 🙂

@zaramzamzam
Copy link
Contributor Author

Hi @sfc-gh-stan I added a PR, but I am unable to select a specific reviewer myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
2 participants