Skip to content

Commit 01dead4

Browse files
authored
SNOW-2435161: Replace importlib guard by sys.modules check in session initialization (#3907)
importlib.util.find_spec checks if a module can be imported in the current environment, while sys.modules checks whether a module was already imported. This check guards a session flag; if modin was already imported, then we need to import modin.config and set the value of the relevant configuration variable. The previous check would improperly import modin if it was present in the environment even if the user did not intend to do so; this triggered a bug in narwhals where the library checked whether "modin" in sys.modules was true instead of "modin.pandas" in sys.modules (code), causing an ImportError even if the user did not intend to use modin at all. Relaxing our check to use sys.modules instead avoids unnecessarily polluting the namespace, avoiding this crash. The narwhals bug that triggered this error was fixed in their codebase as well: narwhals-dev/narwhals#3219
1 parent dd49115 commit 01dead4

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
- Added a fix for floating point precision discrepancies in `interval_day_time_from_parts`.
6767
- Fixed a bug where writing Snowpark pandas dataframes on the pandas backend with a column multiindex to Snowflake with `to_snowflake` would raise `KeyError`.
6868
- Fixed a bug that `DataFrameReader.dbapi` (PuPr) is not compatible with oracledb 3.4.0.
69+
- Fixed a bug where `modin` would unintentionally be imported during session initialization in some scenarios.
6970

7071
#### Improvements
7172

src/snowflake/snowpark/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ def __init__(
755755
)
756756
)
757757

758-
if importlib.util.find_spec("modin"):
758+
if "modin" in sys.modules:
759759
try:
760760
from modin.config import AutoSwitchBackend
761761

0 commit comments

Comments
 (0)