Override run_hooks so pre/post hooks do not emit commit;#392
Open
sdebruyn wants to merge 1 commit into
Open
Conversation
The default run_hooks macro from dbt-adapters emits a bare commit; between hook batches outside the implicit transaction. Fabric Warehouse does not support BEGIN/COMMIT TRAN, so every project using pre-hook or post-hook fails at the run boundary. Add a Fabric-local run_hooks override that drops the commit; statement while preserving the rest of the hook execution logic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #391.
Summary
Adds
dbt/include/fabric/macros/materializations/hooks.sqloverridingrun_hooksso the adapter no longer emitscommit;between hook batches.Background
dbt-adapters' default
run_hooks(atdbt/include/global_project/macros/materializations/hooks.sql) emits acommit;statement at the start of every batch ofinside_transaction=Falsehooks, to close the implicit transaction wrapping a model.Fabric Warehouse does not support
BEGIN/COMMIT TRAN. Thecommit;statement is a T-SQL error, so every model with apre-hookorpost-hookfails at the hook boundary.This is the same problem
dbt-athenasolves the same way — see itshooks.sql.Change
The new
hooks.sqldefines arun_hooksmacro that is identical to the dbt-adapters default with thecommit;statement removed. The dbt-adapters macro is not dispatched, so the override is by macro name (adapter-namespaced macros override global ones).Test plan
dbt runon a project with apre-hookno longer errors at the hook boundarydbt runon a project with apost-hookno longer errors at the hook boundarydbt buildstill runs models inside the wrapping transaction (no regression on theinside_transaction=Truepath)