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

Adding a compatibility mode to ease migration usages #2673

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/snowflake/snowpark/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ class Session:

class RuntimeConfig:
def __init__(self, session: "Session", conf: Dict[str, Any]) -> None:
self.compatibility_mode = False
self.__props_dict = {}
self._session = session
sfc-gh-mrojas marked this conversation as resolved.
Show resolved Hide resolved
self._conf = {
"use_constant_subquery_alias": True,
Expand All @@ -345,7 +347,7 @@ def get(self, key: str, default=None) -> Any:
return getattr(self._session, key)
if hasattr(self._session._conn._conn, key):
return getattr(self._session._conn._conn, key)
return self._conf.get(key, default)
return self._conf.get(key, default) or self.__props_dict.get(key, default)

def is_mutable(self, key: str) -> bool:
with self._lock:
Expand All @@ -369,9 +371,12 @@ def set(self, key: str, value: Any) -> None:
if key in self._conf:
self._conf[key] = value
else:
raise AttributeError(
f'Configuration "{key}" does not exist or is not mutable in runtime'
)
if self.compatibility_mode:
self.__props_dict[key] = value
else:
raise AttributeError(
f'Configuration "{key}" does not exist or is not mutable in runtime'
)

class SessionBuilder:
"""
Expand Down
4 changes: 4 additions & 0 deletions tests/integ/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def test_runtime_config(db_parameters):
in err.value.args[0]
)

# test conf with compatibility_mode=True
session.conf.set("property1", "value1")
assert session.conf.get("property1") == "value1"

session.close()


Expand Down
Loading