Skip to content

Commit 2777c66

Browse files
committed
fix(scheduler): emit CreateNode before evaluating annotated Python models
On the first build of a materialized Python model (or after a breaking change), SnapshotEvaluator._evaluate_snapshot() previously ran CREATE TABLE inside adapter.transaction() before invoking Python model code, keeping the session idle in transaction and holding an AccessExclusiveLock for the full Python execution regardless of pre_ping. Extend Scheduler._dag() to emit a separate CreateNode before EvaluateNode for annotated materialized Python models without pre_statements or post_statements, matching how INCREMENTAL_BY_TIME_RANGE models already separate table creation from evaluation. Part of #6252 Signed-off-by: Vamsi-klu <nrvamsi13@gmail.com>
1 parent 2a157fd commit 2777c66

2 files changed

Lines changed: 392 additions & 4 deletions

File tree

‎sqlmesh/core/scheduler.py‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,9 +722,18 @@ def _dag(
722722
snapshot.is_incremental_by_time_range
723723
or ((not batch_concurrency or batch_concurrency > 1) and batch_size)
724724
or not intervals
725+
or (
726+
snapshot.is_model
727+
and snapshot.is_materialized
728+
and snapshot.model.is_python
729+
and snapshot.model.annotated
730+
and not snapshot.model.pre_statements
731+
and not snapshot.model.post_statements
732+
)
725733
):
726-
# Add a separate node for table creation in case when there multiple concurrent
727-
# evaluation nodes or when there are no intervals to evaluate.
734+
# Add a separate node for table creation when there are multiple concurrent
735+
# evaluation nodes, no intervals to evaluate, or a Python model whose
736+
# execution should not hold a CREATE TABLE transaction open.
728737
create_node = CreateNode(snapshot_name=snapshot.name)
729738
dag.add(create_node, upstream_dependencies)
730739
snapshots_to_create.remove(snapshot.snapshot_id)

0 commit comments

Comments
 (0)