Skip to content

Update docs for transaction handling - snowflake.md#2480

Closed
sspaeti wants to merge 1 commit intodlt-hub:develfrom
sspaeti:patch-1
Closed

Update docs for transaction handling - snowflake.md#2480
sspaeti wants to merge 1 commit intodlt-hub:develfrom
sspaeti:patch-1

Conversation

@sspaeti
Copy link
Copy Markdown
Contributor

@sspaeti sspaeti commented Apr 3, 2025

Description

If you use Snowflake and have transaction settings not set to default, e.g., have set ALTER SESSION SET AUTOCOMMIT = FALSE;, dlt will not work properly and end up having an open session with uncommitted Inserts/merge statements.

I added a note to the docs with this PR to make that clear and not run into errors I did.

Additional Context

Even better would be to explicitly set ALTER SESSION SET AUTOCOMMIT = TRUE; on the insert to destination schema as well as you do for inserting into Staging, where you added ALTER SESSION SET AUTOCOMMIT = TRUE; explicitly.

PS: I added the note to Additional connection options, not sure if that is the best place. Feel free to reorder or let me know where it would make more sense.

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 3, 2025

Deploy Preview for dlt-hub-docs ready!

Name Link
🔨 Latest commit 0c50c14
🔍 Latest deploy log https://app.netlify.com/sites/dlt-hub-docs/deploys/67ee5561924a5b0008441815
😎 Deploy Preview https://deploy-preview-2480--dlt-hub-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@sspaeti
Copy link
Copy Markdown
Contributor Author

sspaeti commented Apr 4, 2025

Just FYI: I'm not sure if the :::note is not working, or the preview (above link isn't correct), but it does not show my additional note on the preview.

@sh-rp sh-rp added the documentation Improvements or additions to documentation label Apr 7, 2025
@rudolfix
Copy link
Copy Markdown
Collaborator

@sspaeti how did you manage to change session settings? each loader job gets a separate connection which is closed after COPY/MERGE command. I'm asking because indeed we didn't start the transaction before SQL job and I changed that: we do it in LoadJob managed run method. MERGE/COPY SQL scripts are not affected.

@rudolfix rudolfix self-assigned this Apr 13, 2025
@rudolfix rudolfix added the question Further information is requested label Apr 13, 2025
@rudolfix rudolfix moved this from Todo to In Progress in dlt core library Apr 13, 2025
@sspaeti
Copy link
Copy Markdown
Contributor Author

sspaeti commented Apr 22, 2025

@rudolfix It was set at a account level (globally). As it can be set on three levels:

  • Account (global) -> alter account set autocommit = false;
  • User -> alter user <username> set autocommit = false;
  • Session -> alter session set autocommit = false;

Whereas session user and account settings overrule. See https://docs.snowflake.com/en/sql-reference/parameters#label-autocommit.

I believe this happens, because you only explicitly set the ALTER SESSION SET AUTOCOMMIT = TRUE; but not for FALSE. Meaning if someone has it the global/account settings set to FALSE, that's when we ran into the issue of open sessions. Small issues, but might be worth mentioning or make it explicit in both way? 🤔

@rudolfix
Copy link
Copy Markdown
Collaborator

@sspaeti now I get it? should we just set autocommit explicitly to TRUE on opening the connection? we do that anyway after comitting/rollbacking the transaction.
if we do that, we just need to mention that we set it explicitly in the docs and user can still have those account settings, right?

@rudolfix
Copy link
Copy Markdown
Collaborator

rudolfix commented May 2, 2025

this PR will explicitly set autocommit on new connection #2593

@rudolfix rudolfix closed this May 2, 2025
@github-project-automation github-project-automation Bot moved this from In Progress to Done in dlt core library May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation question Further information is requested

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants