Skip to content

Commit

Permalink
Explicitly skip last final batch execution when there is only one batch
Browse files Browse the repository at this point in the history
Previously if there was only one batch, we would try to execute _two_
batches. The first batch, and a "last" non existent batch. This would
result in an unhandled exception.
  • Loading branch information
QMalcolm committed Dec 9, 2024
1 parent 00bcce7 commit 6ffed67
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions core/dbt/task/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,18 +768,21 @@ def handle_microbatch_model(
# Wait until all submitted batches have completed
while len(batch_results) != batch_idx:
pass
# Final batch runs once all others complete to ensure post_hook runs at the end
self._submit_batch(
node=node,
adapter=runner.adapter,
relation_exists=relation_exists,
batches=batches,
batch_idx=batch_idx,
batch_results=batch_results,
pool=pool,
force_sequential_run=True,
skip=skip_batches,
)

# Only run "last" batch if there is more than one batch
if len(batches) != 1:
# Final batch runs once all others complete to ensure post_hook runs at the end
self._submit_batch(
node=node,
adapter=runner.adapter,
relation_exists=relation_exists,
batches=batches,
batch_idx=batch_idx,
batch_results=batch_results,
pool=pool,
force_sequential_run=True,
skip=skip_batches,
)

# Finalize run: merge results, track model run, and print final result line
runner.merge_batch_results(result, batch_results)
Expand Down

0 comments on commit 6ffed67

Please sign in to comment.