Skip to content

Commit

Permalink
only run pre_hook on first batch, post_hook on last batch
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk committed Nov 28, 2024
1 parent bec5d57 commit 32002ea
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions core/dbt/task/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,9 +757,16 @@ def _submit_batch(
pool: ThreadPool,
parallel: bool,
):
batch_runner = self.get_runner(deepcopy(node))
node_copy = deepcopy(node)
# Only run pre_hook(s) for first batch
if batch_idx != 0:
node_copy.config.pre_hook = []
# Only run post_hook(s) for last batch
elif batch_idx != len(batches) - 1:
node_copy.config.post_hook = []

batch_runner = self.get_runner(node_copy)
assert isinstance(batch_runner, MicrobatchModelRunner)

batch_runner.set_batch_idx(batch_idx)
batch_runner.set_relation_exists(relation_exists)
batch_runner.set_batches(batches)
Expand Down

0 comments on commit 32002ea

Please sign in to comment.