Skip to content

Commit 0b21555

Browse files
committed
Clarify enable_preview setting
1 parent dbfe468 commit 0b21555

2 files changed

Lines changed: 14 additions & 13 deletions

File tree

sqlmesh_dbt/operations.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,17 @@ def _plan_options(
108108
# this results in the full scope of changes vs prod always being shown on the local branch
109109
create_from=c.PROD,
110110
always_recreate_environment=True,
111-
# setting enable_preview=None enables dev previews of forward_only changes for dbt projects IF the target engine supports cloning
112-
# if we set enable_preview=True here, this enables dev previews in all cases.
113-
# In the case of dbt default INCREMENTAL_UNMANAGED models, this will cause incremental models to be fully rebuilt (potentially a very large computation)
114-
# just to have the results thrown away on promotion to prod because dev previews are not promotable.
111+
# Always enable dev previews for incremental / forward-only models.
112+
# Due to how DBT does incrementals (INCREMENTAL_UNMANAGED on the SQLMesh engine), this will result in the full model being refreshed
113+
# with the entire dataset, which can potentially be very large. If this is undesirable, users have two options:
114+
# - work around this using jinja to conditionally add extra filters to the WHERE clause or a LIMIT to the model query
115+
# - upgrade to SQLMesh's incremental models, where we have variables for the start/end date and inject leak guards to
116+
# limit the amount of data backfilled
115117
#
116-
# TODO: if the user "upgrades" to an INCREMENTAL_BY_TIME_RANGE by defining a "time_column", we can inject leak guards to compute
117-
# just a preview instead of the whole thing like we would in a native project, but the enable_preview setting is at the plan level
118-
# and not the individual model level so we currently have no way of doing this selectively
119-
enable_preview=None,
118+
# Note: enable_preview=True is *different* behaviour to the `sqlmesh` CLI, which uses enable_preview=None.
119+
# This means the `sqlmesh` CLI will only enable dev previews for dbt projects if the target adapter supports cloning,
120+
# whereas we enable it unconditionally here
121+
enable_preview=True,
120122
)
121123
)
122124

tests/dbt/cli/test_operations.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,7 @@ def test_run_option_mapping_dev(jaffle_shop_duckdb: Path):
197197
assert plan.include_unmodified is False
198198
assert plan.context_diff.create_from == "prod"
199199
assert plan.context_diff.is_new_environment is True
200-
assert (
201-
console.plan_builder._enable_preview is False
202-
) # duckdb doesnt support cloning so dev previews are not enabled for dbt projects
200+
assert console.plan_builder._enable_preview is True
203201
assert plan.end_bounded is True
204202
assert plan.ignore_cron is False
205203
assert plan.skip_backfill is False
@@ -213,7 +211,7 @@ def test_run_option_mapping_dev(jaffle_shop_duckdb: Path):
213211
assert plan.include_unmodified is False
214212
assert plan.context_diff.create_from == "prod"
215213
assert plan.context_diff.is_new_environment is True
216-
assert console.plan_builder._enable_preview is False
214+
assert console.plan_builder._enable_preview is True
217215
assert plan.end_bounded is True
218216
assert plan.ignore_cron is False
219217
assert plan.skip_backfill is True
@@ -227,8 +225,9 @@ def test_run_option_mapping_dev(jaffle_shop_duckdb: Path):
227225
assert plan.include_unmodified is False
228226
assert plan.context_diff.create_from == "prod"
229227
assert plan.context_diff.is_new_environment is True
230-
assert console.plan_builder._enable_preview is False
228+
assert console.plan_builder._enable_preview is True
231229
# dev plans with --select have run=True, ignore_cron=True set
230+
# as opposed to dev plans that dont have a specific selector
232231
assert plan.end_bounded is False
233232
assert plan.ignore_cron is True
234233
assert plan.skip_backfill is False

0 commit comments

Comments
 (0)