Skip to content

fix: guard run_hooks commit with @@trancount check for autocommit safety#709

Merged
axellpadilla merged 1 commit into
masterfrom
FIX/444-wrong-commit-post-hook
Jun 15, 2026
Merged

fix: guard run_hooks commit with @@trancount check for autocommit safety#709
axellpadilla merged 1 commit into
masterfrom
FIX/444-wrong-commit-post-hook

Conversation

@axellpadilla

@axellpadilla axellpadilla commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

dbt-core's run_hooks macro emits a bare 'commit;' before running inside_transaction=False hooks (after_commit). With autocommit=True there is no open SQL Server transaction, causing error 3902. Closes #444

Override run_hooks for the sqlserver adapter, replacing the bare commit with 'if @@trancount > 0 commit;' which only commits when a transaction is actually open.

Add TestAfterCommitModelHook regression test that creates a table model with an after_commit post-hook and verifies it runs without error.

Follow up: #708

dbt-core's run_hooks macro emits a bare 'commit;' before running
inside_transaction=False hooks (after_commit). With autocommit=True
there is no open SQL Server transaction, causing error 3902.

Override run_hooks for the sqlserver adapter, replacing the bare
commit with 'if @@trancount > 0 commit;' which only commits when
a transaction is actually open.

Add TestAfterCommitModelHook regression test that creates a table
model with an after_commit post-hook and verifies it runs without
error.
@axellpadilla axellpadilla enabled auto-merge June 15, 2026 02:27
@axellpadilla axellpadilla merged commit d8fb26f into master Jun 15, 2026
16 checks passed
@axellpadilla axellpadilla deleted the FIX/444-wrong-commit-post-hook branch June 15, 2026 02:28
@axellpadilla axellpadilla added this to the v1.10.1rc1 milestone Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to use post_hook after_commit

1 participant