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

Set default isolation level to AUTOCOMMIT for snowflake #1719

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Changes from all commits
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
12 changes: 12 additions & 0 deletions src/core/trulens/core/database/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ def __init__(

def _reload_engine(self):
if self.engine is None:
# Check if the dialect is snowflake and set isolation_level
if (
"url" in self.engine_params
and "snowflake" in self.engine_params["url"]
sfc-gh-dhuang marked this conversation as resolved.
Show resolved Hide resolved
):
temp_engine = sa.create_engine(**self.engine_params)
if temp_engine.dialect.name == "snowflake":
self.engine_params.setdefault(
"isolation_level", "AUTOCOMMIT"
)
# Dispose of the temporary engine
temp_engine.dispose()
Copy link
Contributor

Choose a reason for hiding this comment

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

curious how this works. is the isolation level somehow retained after you dispose of the temporary engine?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, isolation_level will be set in self.engine_params and this will be used (in the case of snowflake being the DB) when creating the new engine on lines below

For context, I agree this is a bit ugly but I think the overhead of creating and disposing a temp_engine is okay as it's just opening and closing a DB connection.

self.engine = sa.create_engine(**self.engine_params)
self.session = sessionmaker(self.engine, **self.session_params)

Expand Down