Skip to content

Commit 1bd81f5

Browse files
authored
fix falsy evaluation of build_after.count (#12136)
1 parent 65a122b commit 1bd81f5

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Fixes
2+
body: Fix parse error when build_after.count set to 0
3+
time: 2025-11-03T13:40:34.653439-05:00
4+
custom:
5+
Author: michelleark
6+
Issue: "12136"

core/dbt/artifacts/resources/v1/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ def __post_init__(self):
8484
if (
8585
self.freshness
8686
and self.freshness.build_after.period
87-
and not self.freshness.build_after.count
87+
and self.freshness.build_after.count is None
8888
):
8989
raise ValidationError(
9090
"`freshness.build_after` must have a value for `count` if a `period` is provided"
9191
)
9292
elif (
9393
self.freshness
94-
and self.freshness.build_after.count
94+
and self.freshness.build_after.count is not None
9595
and not self.freshness.build_after.period
9696
):
9797
raise ValidationError(

tests/functional/model_config/test_freshness_config.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@
100100
"""
101101

102102

103+
models__model_freshness_schema_yml_build_period_has_0_count = """
104+
models:
105+
- name: model_a
106+
description: Model with only model freshness defined
107+
config:
108+
freshness:
109+
build_after:
110+
period: day
111+
count: 0
112+
"""
113+
114+
103115
models__model_freshness_schema_yml_build_count_requires_period = """
104116
models:
105117
- name: model_a
@@ -159,6 +171,18 @@ def test_model_freshness_configs(self, project):
159171
assert expected_msg in str(excinfo.value)
160172

161173

174+
class TestModelFreshnessConfigParseBuildPeriodHas0Count:
175+
@pytest.fixture(scope="class")
176+
def models(self):
177+
return {
178+
"schema.yml": models__model_freshness_schema_yml_build_period_has_0_count,
179+
"model_a.sql": models__no_freshness_sql,
180+
}
181+
182+
def test_model_freshness_configs(self, project):
183+
run_dbt(["parse"])
184+
185+
162186
class TestModelFreshnessConfigParseBuildCountRequiresPeriod:
163187
@pytest.fixture(scope="class")
164188
def models(self):

0 commit comments

Comments
 (0)