Support aliased configs jsonschemas (#12291) (#12292)

This commit is contained in:
github-actions[bot]
2025-12-17 13:13:57 -05:00
committed by GitHub
parent 07f02943cd
commit c9a6157982
3 changed files with 68 additions and 2 deletions

View File

@@ -0,0 +1,6 @@
kind: Fixes
body: Do not raise deprecation warning when encountering dataset or project configs for bigquery
time: 2025-12-17T10:59:18.372968-05:00
custom:
Author: michelleark
Issue: "12285"

View File

@@ -37,6 +37,10 @@ _HIERARCHICAL_CONFIG_KEYS = {
"unit_tests",
}
_ADAPTER_TO_CONFIG_ALIASES = {
"bigquery": ["dataset", "project"],
}
def load_json_from_package(jsonschema_type: str, filename: str) -> Dict[str, Any]:
"""Loads a JSON file from within a package."""
@@ -106,6 +110,16 @@ def _validate_with_schema(
return validator.iter_errors(json)
def _get_allowed_config_key_aliases() -> List[str]:
config_aliases = []
invocation_context = get_invocation_context()
for adapter in invocation_context.adapter_types:
if adapter in _ADAPTER_TO_CONFIG_ALIASES:
config_aliases.extend(_ADAPTER_TO_CONFIG_ALIASES[adapter])
return config_aliases
def _get_allowed_config_fields_from_error_path(
yml_schema: Dict[str, Any], error_path: List[Union[str, int]]
) -> Optional[List[str]]:
@@ -135,6 +149,7 @@ def _get_allowed_config_fields_from_error_path(
][0]["$ref"].split("/")[-1]
allowed_config_fields = list(set(yml_schema["definitions"][config_field_name]["properties"]))
allowed_config_fields.extend(_get_allowed_config_key_aliases())
return allowed_config_fields
@@ -169,7 +184,6 @@ def jsonschema_validate(schema: Dict[str, Any], json: Dict[str, Any], file_path:
continue
if key == "overrides" and key_path.startswith("sources"):
deprecations.warn(
"source-override-deprecation",
source_name=key_path.split(".")[-1],
@@ -205,6 +219,9 @@ def jsonschema_validate(schema: Dict[str, Any], json: Dict[str, Any], file_path:
keys = _additional_properties_violation_keys(sub_error)
key_path = error_path_to_string(error)
for key in keys:
if key in _get_allowed_config_key_aliases():
continue
deprecations.warn(
"custom-key-in-config-deprecation",
key=key,

View File

@@ -1,9 +1,17 @@
import pytest
from dbt.deprecations import (
CustomKeyInConfigDeprecation,
CustomKeyInObjectDeprecation,
GenericJSONSchemaValidationDeprecation,
active_deprecations,
reset_deprecations,
)
from dbt.jsonschemas.jsonschemas import (
jsonschema_validate,
resources_schema,
validate_model_config,
)
from dbt.jsonschemas.jsonschemas import validate_model_config
from dbt.tests.util import safe_set_invocation_context
from dbt_common.context import get_invocation_context
from dbt_common.events.event_manager_client import add_callback_to_manager
@@ -48,3 +56,38 @@ class TestValidateModelConfigNoError:
assert len(ckicd_catcher.caught_events) == 1
assert ckicd_catcher.caught_events[0].data.key == "non_existent_config"
assert len(gjsvd_catcher.caught_events) == 0
class TestValidateJsonSchema:
@pytest.fixture(scope="class")
def model_bigquery_alias_config_contents(self):
return {
"models": [
{
"name": "model_1",
"config": {
"dataset": "dataset_1",
"project": "project_1",
},
}
],
}
def test_validate_json_schema_no_error_aliases(self, model_bigquery_alias_config_contents):
reset_deprecations()
safe_set_invocation_context()
get_invocation_context().uses_adapter("bigquery")
jsonschema_validate(resources_schema(), model_bigquery_alias_config_contents, "test.yml")
assert active_deprecations == {}
def test_validate_json_schema_has_error_aliases(self, model_bigquery_alias_config_contents):
reset_deprecations()
safe_set_invocation_context()
# Set to adapter that doesn't support aliases specified
get_invocation_context().uses_adapter("snowflake")
jsonschema_validate(resources_schema(), model_bigquery_alias_config_contents, "test.yml")
assert active_deprecations == {"custom-key-in-config-deprecation": 2}