-
Notifications
You must be signed in to change notification settings - Fork 141
SNOW-2317965: Refactor context_configure_development_features #4041
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
base: main
Are you sure you want to change the base?
Conversation
src/snowflake/snowpark/session.py
Outdated
| raise SnowparkClientExceptionMessages.SERVER_NO_DEFAULT_SESSION() | ||
| if require_at_least_one: | ||
| raise SnowparkClientExceptionMessages.SERVER_NO_DEFAULT_SESSION() | ||
| return [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type mismatch: Returns an empty list [] but the function signature declares return type as Set["Session"]. This should return an empty set instead.
return set()While iteration works with both lists and sets, this type inconsistency could cause runtime errors if callers use Set-specific methods like .add(), .union(), etc. or type checkers will flag this as an error.
| return [] | |
| return set() |
Spotted by Graphite Agent
Is this helpful? React 👍 or 👎 to let us know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated manually
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
| sessions = snowflake.snowpark.session._get_active_sessions( | ||
| require_at_least_one=False | ||
| ) | ||
| try: | ||
| session = get_active_session() | ||
| if session is None: | ||
| _logger.warning( | ||
| "No active session found. Please create a session first and call " | ||
| "`configure_development_features()` after creating the session.", | ||
| ) | ||
| return | ||
| _enable_dataframe_trace_on_error = enable_dataframe_trace_on_error | ||
| _enable_trace_sql_errors_to_dataframe = enable_trace_sql_errors_to_dataframe | ||
| session.ast_enabled = True | ||
| for active_session in sessions: | ||
| active_session._set_ast_enabled_internal(True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Race condition: _get_active_sessions() returns the actual _active_sessions set without holding the lock during iteration. If another thread adds/removes a session while iterating at line 86, it will raise RuntimeError: Set changed size during iteration.
Fix by making a copy:
sessions = snowflake.snowpark.session._get_active_sessions(
require_at_least_one=False
).copy() # Make a copy to avoid iteration issuesAlternatively, the _get_active_sessions() function should return a copy instead of the actual set to prevent unsafe access to the mutex-protected data structure.
| sessions = snowflake.snowpark.session._get_active_sessions( | |
| require_at_least_one=False | |
| ) | |
| try: | |
| session = get_active_session() | |
| if session is None: | |
| _logger.warning( | |
| "No active session found. Please create a session first and call " | |
| "`configure_development_features()` after creating the session.", | |
| ) | |
| return | |
| _enable_dataframe_trace_on_error = enable_dataframe_trace_on_error | |
| _enable_trace_sql_errors_to_dataframe = enable_trace_sql_errors_to_dataframe | |
| session.ast_enabled = True | |
| for active_session in sessions: | |
| active_session._set_ast_enabled_internal(True) | |
| sessions = snowflake.snowpark.session._get_active_sessions( | |
| require_at_least_one=False | |
| ).copy() # Make a copy to avoid iteration issues | |
| try: | |
| for active_session in sessions: | |
| active_session._set_ast_enabled_internal(True) |
Spotted by Graphite Agent
Is this helpful? React 👍 or 👎 to let us know.
Which Jira issue is this PR addressing? Make sure that there is an accompanying issue to your PR.
Fixes SNOW-2317965
Fill out the following pre-review checklist:
Please describe how your code solves the related issue.