Skip to content

Commit 82ead86

Browse files
committed
Clarify enable_preview setting
1 parent 9672130 commit 82ead86

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

sqlmesh_dbt/operations.py

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

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)