Skip to content

Override run_hooks so pre/post hooks do not emit commit;#392

Open
sdebruyn wants to merge 1 commit into
microsoft:mainfrom
sdebruyn:up-04
Open

Override run_hooks so pre/post hooks do not emit commit;#392
sdebruyn wants to merge 1 commit into
microsoft:mainfrom
sdebruyn:up-04

Conversation

@sdebruyn
Copy link
Copy Markdown
Collaborator

Fixes #391.

Summary

Adds dbt/include/fabric/macros/materializations/hooks.sql overriding run_hooks so the adapter no longer emits commit; between hook batches.

Background

dbt-adapters' default run_hooks (at dbt/include/global_project/macros/materializations/hooks.sql) emits a commit; statement at the start of every batch of inside_transaction=False hooks, to close the implicit transaction wrapping a model.

Fabric Warehouse does not support BEGIN/COMMIT TRAN. The commit; statement is a T-SQL error, so every model with a pre-hook or post-hook fails at the hook boundary.

This is the same problem dbt-athena solves the same way — see its hooks.sql.

Change

The new hooks.sql defines a run_hooks macro that is identical to the dbt-adapters default with the commit; 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 run on a project with a pre-hook no longer errors at the hook boundary
  • dbt run on a project with a post-hook no longer errors at the hook boundary
  • dbt build still runs models inside the wrapping transaction (no regression on the inside_transaction=True path)
  • Snapshot + on-run-start / on-run-end hooks still execute

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.
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.

Pre/post hooks fail at every run boundary: dbt-adapters' default run_hooks emits commit; that Fabric Warehouse cannot execute

1 participant