Skip to content

Commit fe876a3

Browse files
github-actions[bot]MichelleArkQMalcolm
authored
move TestConfig.post_init logic to finalize_and_validate to respect hierarchical configs (#11730) (#11738)
(cherry picked from commit 0fff576) Co-authored-by: Michelle Ark <[email protected]> Co-authored-by: Quigley Malcolm <[email protected]>
1 parent 3abb115 commit fe876a3

File tree

4 files changed

+125
-1
lines changed

4 files changed

+125
-1
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 store_failures hierarachical config parsing
3+
time: 2025-06-12T14:51:59.358498-04:00
4+
custom:
5+
Author: michelleark
6+
Issue: "10165"

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class TestConfig(NodeAndTestConfig):
181181
warn_if: str = "!= 0"
182182
error_if: str = "!= 0"
183183

184-
def __post_init__(self):
184+
def finalize_and_validate(self):
185185
"""
186186
The presence of a setting for `store_failures_as` overrides any existing setting for `store_failures`,
187187
regardless of level of granularity. If `store_failures_as` is not set, then `store_failures` takes effect.
@@ -207,6 +207,7 @@ def __post_init__(self):
207207
but still allow for backwards compatibility for `store_failures`.
208208
See https://github.com/dbt-labs/dbt-core/issues/6914 for more information.
209209
"""
210+
super().finalize_and_validate()
210211

211212
# if `store_failures_as` is not set, it gets set by `store_failures`
212213
# the settings below mimic existing behavior prior to `store_failures_as`
@@ -229,6 +230,8 @@ def __post_init__(self):
229230
else:
230231
self.store_failures = get_store_failures_map.get(self.store_failures_as, True)
231232

233+
return self
234+
232235
@classmethod
233236
def same_contents(cls, unrendered: Dict[str, Any], other: Dict[str, Any]) -> bool:
234237
"""This is like __eq__, except it explicitly checks certain fields."""

tests/functional/schema_tests/fixtures.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,3 +1273,31 @@
12731273
data_tests:
12741274
- my_custom_test
12751275
"""
1276+
1277+
store_failures_models__my_model_sql = """
1278+
select 1 as id
1279+
"""
1280+
1281+
store_failures_models_true__config_yml = """
1282+
version: 2
1283+
models:
1284+
- name: my_model
1285+
columns:
1286+
- name: id
1287+
tests:
1288+
- not_null:
1289+
config:
1290+
store_failures: true
1291+
"""
1292+
1293+
store_failures_models_false__config_yml = """
1294+
version: 2
1295+
models:
1296+
- name: my_model
1297+
columns:
1298+
- name: id
1299+
tests:
1300+
- not_null:
1301+
config:
1302+
store_failures: false
1303+
"""

tests/functional/schema_tests/test_schema_v2_tests.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@
7777
quote_required_models__model_sql,
7878
quote_required_models__schema_yml,
7979
seeds__some_seed_csv,
80+
store_failures_models__my_model_sql,
81+
store_failures_models_false__config_yml,
82+
store_failures_models_true__config_yml,
8083
test_context_macros__custom_schema_tests_sql,
8184
test_context_macros__my_test_sql,
8285
test_context_macros__test_my_datediff_sql,
@@ -1128,3 +1131,87 @@ def test_macro_resolution_test_namespace(
11281131
# leading to the macro being missing in the TestNamespace
11291132
run_dbt(["deps"])
11301133
run_dbt(["parse"])
1134+
1135+
1136+
class TestSchemaTestStoreFailuresTrueParsing:
1137+
@pytest.fixture(scope="class")
1138+
def models(self):
1139+
return {
1140+
"schema.yml": store_failures_models_true__config_yml,
1141+
"my_model.sql": store_failures_models__my_model_sql,
1142+
}
1143+
1144+
def test_parse_store_failures_True_as_table(self, project):
1145+
manifest = run_dbt(["parse"])
1146+
test_node = [
1147+
node for node in manifest.nodes.values() if "not_null_my_model_id" in node.fqn
1148+
][0]
1149+
1150+
assert test_node.config.store_failures
1151+
assert test_node.config.store_failures_as == "table"
1152+
1153+
1154+
class TestSchemaTestStoreFailuresFalseParsing:
1155+
@pytest.fixture(scope="class")
1156+
def models(self):
1157+
return {
1158+
"schema.yml": store_failures_models_false__config_yml,
1159+
"my_model.sql": store_failures_models__my_model_sql,
1160+
}
1161+
1162+
def test_parse_store_failures_False_as_ephemeral(self, project):
1163+
manifest = run_dbt(["parse"])
1164+
test_node = [
1165+
node for node in manifest.nodes.values() if "not_null_my_model_id" in node.fqn
1166+
][0]
1167+
1168+
assert not test_node.config.store_failures
1169+
assert test_node.config.store_failures_as == "ephemeral"
1170+
1171+
1172+
class TestSchemaTestStoreFailuresTrueHierarchicalParsing:
1173+
@pytest.fixture(scope="class")
1174+
def models(self):
1175+
return {
1176+
"schema.yml": store_failures_models_true__config_yml,
1177+
"my_model.sql": store_failures_models__my_model_sql,
1178+
}
1179+
1180+
@pytest.fixture(scope="class")
1181+
def project_config_update(self):
1182+
return {
1183+
"tests": {"+store_failures": False},
1184+
}
1185+
1186+
def test_parse_store_failures_True_as_table(self, project):
1187+
manifest = run_dbt(["parse"])
1188+
test_node = [
1189+
node for node in manifest.nodes.values() if "not_null_my_model_id" in node.fqn
1190+
][0]
1191+
1192+
assert test_node.config.store_failures
1193+
assert test_node.config.store_failures_as == "table"
1194+
1195+
1196+
class TestSchemaTestStoreFailuresFalseHierarchicalParsing:
1197+
@pytest.fixture(scope="class")
1198+
def models(self):
1199+
return {
1200+
"schema.yml": store_failures_models_false__config_yml,
1201+
"my_model.sql": store_failures_models__my_model_sql,
1202+
}
1203+
1204+
@pytest.fixture(scope="class")
1205+
def project_config_update(self):
1206+
return {
1207+
"tests": {"+store_failures": True},
1208+
}
1209+
1210+
def test_parse_store_failures_False_as_ephemeral(self, project):
1211+
manifest = run_dbt(["parse"])
1212+
test_node = [
1213+
node for node in manifest.nodes.values() if "not_null_my_model_id" in node.fqn
1214+
][0]
1215+
1216+
assert not test_node.config.store_failures
1217+
assert test_node.config.store_failures_as == "ephemeral"

0 commit comments

Comments
 (0)