avoid raising custom-key-in-config-deprecation for pre/post-hook model SQL config validation (#12244)

This commit is contained in:
Michelle Ark
2025-12-02 14:22:02 -05:00
committed by GitHub
parent 5d56a052a7
commit 12b04e7d2f
4 changed files with 46 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
kind: Fixes
body: ':bug: :snowman: Fix false positive deprecation warning of pre/post-hook SQL configs'
time: 2025-12-02T13:37:05.012112-05:00
custom:
Author: michelleark
Issue: "12244"

View File

@@ -265,6 +265,11 @@ def validate_model_config(config: Dict[str, Any], file_path: str) -> None:
if len(error.path) == 0:
key_path = error_path_to_string(error)
for key in keys:
# Special case for pre/post hook keys as they are updated during config parsing
# from the user-provided pre_hook/post_hook to pre-hook/post-hook keys.
# Avoids false positives as described in https://github.com/dbt-labs/dbt-core/issues/12087
if key in ("post-hook", "pre-hook"):
continue
deprecations.warn(
"custom-key-in-config-deprecation",
key=key,

View File

@@ -28,6 +28,11 @@ macros__custom_test_sql = """
{% endtest %}
"""
models_pre_post_hook_in_config_sql = """
{{ config(post_hook="select 1", pre_hook="select 2") }}
select 1 as id
"""
bad_name_yaml = """
version: 2
@@ -197,6 +202,16 @@ models:
my_custom_property: "It's over, I have the high ground"
"""
pre_post_hook_in_config_yaml = """
models:
- name: model_with_hook_configs
config:
post_hook: "select 1"
pre_hook: "select 2"
"""
property_moved_to_config_yaml = """
models:
- name: models_trivial

View File

@@ -41,8 +41,10 @@ from tests.functional.deprecations.fixtures import (
invalid_deprecation_date_yaml,
models_custom_key_in_config_non_static_parser_sql,
models_custom_key_in_config_sql,
models_pre_post_hook_in_config_sql,
models_trivial__model_sql,
multiple_custom_keys_in_config_yaml,
pre_post_hook_in_config_yaml,
property_moved_to_config_yaml,
test_missing_arguments_property_yaml,
test_with_arguments_yaml,
@@ -904,3 +906,21 @@ class TestPropertyMovedToConfigDeprecation:
callbacks=[event_catcher.catch],
)
assert len(event_catcher.caught_events) == 7
class TestPrePostHookNoFalsePositiveDeprecation:
@pytest.fixture(scope="class")
def models(self):
return {
"model_hook_configs.sql": models_pre_post_hook_in_config_sql,
"schema.yml": pre_post_hook_in_config_yaml,
}
@mock.patch("dbt.jsonschemas.jsonschemas._JSONSCHEMA_SUPPORTED_ADAPTERS", {"postgres"})
def test_pre_post_hook_no_false_positive_deprecation(self, project):
event_catcher = EventCatcher(CustomKeyInConfigDeprecation)
run_dbt(
["parse", "--no-partial-parse", "--show-all-deprecations"],
callbacks=[event_catcher.catch],
)
assert len(event_catcher.caught_events) == 0