Skip to content

Commit 008f7d7

Browse files
committed
Fix: Don't set the is_incremental flag for non-incremental dbt models (#3616)
1 parent 920ad1c commit 008f7d7

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

sqlmesh/dbt/builtin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def create_builtin_globals(
372372
builtin_globals["var"] = Var(variables)
373373

374374
snapshot = jinja_globals.pop("snapshot", None)
375-
is_incremental = bool(snapshot.intervals) if snapshot else False
375+
is_incremental = bool(snapshot.intervals) and snapshot.is_incremental if snapshot else False
376376
builtin_globals["is_incremental"] = lambda: is_incremental
377377

378378
builtin_globals["builtins"] = AttributeDict(

tests/dbt/test_transformation.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,13 +1125,40 @@ def test_is_incremental(sushi_test_project: Project, assert_exp_eq, mocker):
11251125

11261126
snapshot = mocker.Mock()
11271127
snapshot.intervals = [1]
1128+
snapshot.is_incremental = True
11281129

11291130
assert_exp_eq(
11301131
model_config.to_sqlmesh(context).render_query_or_raise(snapshot=snapshot).sql(),
11311132
'SELECT 1 AS "one" FROM "tbl_a" AS "tbl_a" WHERE "ds" > (SELECT MAX("ds") FROM "model" AS "model")',
11321133
)
11331134

11341135

1136+
@pytest.mark.xdist_group("dbt_manifest")
1137+
def test_is_incremental_non_incremental_model(sushi_test_project: Project, assert_exp_eq, mocker):
1138+
model_config = ModelConfig(
1139+
name="model",
1140+
package_name="package",
1141+
schema="sushi",
1142+
alias="some_table",
1143+
sql="""
1144+
SELECT 1 AS one FROM tbl_a
1145+
{% if is_incremental() %}
1146+
WHERE ds > (SELECT MAX(ds) FROM model)
1147+
{% endif %}
1148+
""",
1149+
)
1150+
context = sushi_test_project.context
1151+
1152+
snapshot = mocker.Mock()
1153+
snapshot.intervals = [1]
1154+
snapshot.is_incremental = False
1155+
1156+
assert_exp_eq(
1157+
model_config.to_sqlmesh(context).render_query_or_raise(snapshot=snapshot).sql(),
1158+
'SELECT 1 AS "one" FROM "tbl_a" AS "tbl_a"',
1159+
)
1160+
1161+
11351162
@pytest.mark.xdist_group("dbt_manifest")
11361163
def test_dbt_max_partition(sushi_test_project: Project, assert_exp_eq, mocker: MockerFixture):
11371164
model_config = ModelConfig(

0 commit comments

Comments
 (0)