Turn on jsonschema-based deprecations by default, based on adapter support (#12240)

This commit is contained in:
Michelle Ark
2025-12-02 12:37:37 -05:00
committed by GitHub
parent 62a8ea05a6
commit 5d56a052a7
7 changed files with 6 additions and 30 deletions

View File

@@ -0,0 +1,6 @@
kind: Features
body: Raise jsonschema-based deprecation warnings by default
time: 2025-12-01T16:52:09.354436-05:00
custom:
Author: michelleark
Issue: 12240

View File

@@ -1,5 +1,4 @@
import json
import os
import re
from datetime import date, datetime
from pathlib import Path
@@ -141,9 +140,6 @@ def _get_allowed_config_fields_from_error_path(
def _can_run_validations() -> bool:
if not os.environ.get("DBT_ENV_PRIVATE_RUN_JSONSCHEMA_VALIDATIONS"):
return False
invocation_context = get_invocation_context()
return invocation_context.adapter_types.issubset(_JSONSCHEMA_SUPPORTED_ADAPTERS)

View File

@@ -316,7 +316,6 @@ class TestDeprecatedInvalidDeprecationDate:
"models.yml": invalid_deprecation_date_yaml,
}
@mock.patch.dict(os.environ, {"DBT_ENV_PRIVATE_RUN_JSONSCHEMA_VALIDATIONS": "True"})
def test_deprecated_invalid_deprecation_date(self, project):
event_catcher = EventCatcher(GenericJSONSchemaValidationDeprecation)
note_catcher = EventCatcher(Note)
@@ -362,7 +361,6 @@ class TestCustomKeyInConfigDeprecation:
}
@mock.patch("dbt.jsonschemas.jsonschemas._JSONSCHEMA_SUPPORTED_ADAPTERS", {"postgres"})
@mock.patch.dict(os.environ, {"DBT_ENV_PRIVATE_RUN_JSONSCHEMA_VALIDATIONS": "True"})
def test_custom_key_in_config_deprecation(self, project):
event_catcher = EventCatcher(CustomKeyInConfigDeprecation)
run_dbt(
@@ -384,7 +382,6 @@ class TestCustomKeyInConfigSQLDeprecation:
}
@mock.patch("dbt.jsonschemas.jsonschemas._JSONSCHEMA_SUPPORTED_ADAPTERS", {"postgres"})
@mock.patch.dict(os.environ, {"DBT_ENV_PRIVATE_RUN_JSONSCHEMA_VALIDATIONS": "True"})
def test_custom_key_in_config_sql_deprecation(self, project):
event_catcher = EventCatcher(CustomKeyInConfigDeprecation)
run_dbt(
@@ -415,7 +412,6 @@ class TestMultipleCustomKeysInConfigDeprecation:
}
@mock.patch("dbt.jsonschemas.jsonschemas._JSONSCHEMA_SUPPORTED_ADAPTERS", {"postgres"})
@mock.patch.dict(os.environ, {"DBT_ENV_PRIVATE_RUN_JSONSCHEMA_VALIDATIONS": "True"})
def test_multiple_custom_keys_in_config_deprecation(self, project):
event_catcher = EventCatcher(CustomKeyInConfigDeprecation)
run_dbt(
@@ -442,7 +438,6 @@ class TestCustomKeyInObjectDeprecation:
}
@mock.patch("dbt.jsonschemas.jsonschemas._JSONSCHEMA_SUPPORTED_ADAPTERS", {"postgres"})
@mock.patch.dict(os.environ, {"DBT_ENV_PRIVATE_RUN_JSONSCHEMA_VALIDATIONS": "True"})
def test_custom_key_in_object_deprecation(self, project):
event_catcher = EventCatcher(CustomKeyInObjectDeprecation)
run_dbt(["parse", "--no-partial-parse"], callbacks=[event_catcher.catch])
@@ -486,7 +481,6 @@ class TestCustomOutputPathInSourceFreshnessDeprecation:
class TestHappyPathProjectHasNoDeprecations:
@mock.patch.dict(os.environ, {"DBT_ENV_PRIVATE_RUN_JSONSCHEMA_VALIDATIONS": "True"})
@mock.patch("dbt.jsonschemas.jsonschemas._JSONSCHEMA_SUPPORTED_ADAPTERS", {"postgres"})
def test_happy_path_project_has_no_deprecations(self, happy_path_project):
event_cathcer = EventCatcher(DeprecationsSummary)
@@ -498,7 +492,6 @@ class TestHappyPathProjectHasNoDeprecations:
class TestBaseProjectHasNoDeprecations:
@mock.patch.dict(os.environ, {"DBT_ENV_PRIVATE_RUN_JSONSCHEMA_VALIDATIONS": "True"})
@mock.patch("dbt.jsonschemas.jsonschemas._JSONSCHEMA_SUPPORTED_ADAPTERS", {"postgres"})
def test_base_project_has_no_deprecations(self, project):
event_cathcer = EventCatcher(DeprecationsSummary)
@@ -707,7 +700,6 @@ class TestMissingPlusPrefixDeprecation:
def project_config_update(self):
return {"seeds": {"path": {"enabled": True}}}
@mock.patch.dict(os.environ, {"DBT_ENV_PRIVATE_RUN_JSONSCHEMA_VALIDATIONS": "True"})
@mock.patch("dbt.jsonschemas.jsonschemas._JSONSCHEMA_SUPPORTED_ADAPTERS", {"postgres"})
def test_missing_plus_prefix_deprecation(self, project):
event_catcher = EventCatcher(MissingPlusPrefixDeprecation)
@@ -721,7 +713,6 @@ class TestMissingPlusPrefixDeprecationSubPath:
def project_config_update(self):
return {"seeds": {"path": {"+enabled": True, "sub_path": {"enabled": True}}}}
@mock.patch.dict(os.environ, {"DBT_ENV_PRIVATE_RUN_JSONSCHEMA_VALIDATIONS": "True"})
@mock.patch("dbt.jsonschemas.jsonschemas._JSONSCHEMA_SUPPORTED_ADAPTERS", {"postgres"})
def test_missing_plus_prefix_deprecation_sub_path(self, project):
event_catcher = EventCatcher(MissingPlusPrefixDeprecation)
@@ -735,7 +726,6 @@ class TestMissingPlusPrefixDeprecationCustomConfig:
def project_config_update(self):
return {"seeds": {"path": {"custom_config": True, "sub_path": {"+enabled": True}}}}
@mock.patch.dict(os.environ, {"DBT_ENV_PRIVATE_RUN_JSONSCHEMA_VALIDATIONS": "True"})
@mock.patch("dbt.jsonschemas.jsonschemas._JSONSCHEMA_SUPPORTED_ADAPTERS", {"postgres"})
def test_missing_plus_prefix_deprecation_sub_path(self, project):
event_catcher = EventCatcher(MissingPlusPrefixDeprecation)
@@ -749,7 +739,6 @@ class TestCustomConfigInDbtProjectYmlNoDeprecation:
def project_config_update(self):
return {"seeds": {"path": {"+custom_config": True}}}
@mock.patch.dict(os.environ, {"DBT_ENV_PRIVATE_RUN_JSONSCHEMA_VALIDATIONS": "True"})
@mock.patch("dbt.jsonschemas.jsonschemas._JSONSCHEMA_SUPPORTED_ADAPTERS", {"postgres"})
def test_missing_plus_prefix_deprecation_sub_path(self, project):
note_catcher = EventCatcher(Note)
@@ -782,10 +771,6 @@ class TestJsonSchemaValidationGating:
dbt_private_run_jsonschema_validations: bool,
expected_events: int,
) -> None:
mocker.patch.dict(
os.environ,
{"DBT_ENV_PRIVATE_RUN_JSONSCHEMA_VALIDATIONS": dbt_private_run_jsonschema_validations},
)
if postgres_is_valid:
supported_adapters_with_postgres = {
@@ -911,7 +896,6 @@ class TestPropertyMovedToConfigDeprecation:
"models.yml": property_moved_to_config_yaml,
}
@mock.patch.dict(os.environ, {"DBT_ENV_PRIVATE_RUN_JSONSCHEMA_VALIDATIONS": "True"})
@mock.patch("dbt.jsonschemas.jsonschemas._JSONSCHEMA_SUPPORTED_ADAPTERS", {"postgres"})
def test_property_moved_to_config_deprecation(self, project):
event_catcher = EventCatcher(PropertyMovedToConfigDeprecation)

View File

@@ -1,4 +1,3 @@
import os
from datetime import datetime, timedelta, timezone
from unittest import mock
@@ -99,7 +98,6 @@ class TestSourceOverride:
return insert_id + 1
@mock.patch("dbt.jsonschemas.jsonschemas._JSONSCHEMA_SUPPORTED_ADAPTERS", {"postgres"})
@mock.patch.dict(os.environ, {"DBT_ENV_PRIVATE_RUN_JSONSCHEMA_VALIDATIONS": "True"})
def test_source_overrides(self, project):
insert_id = 101

View File

@@ -1,4 +1,3 @@
import os
from unittest import mock
import yaml
@@ -28,7 +27,6 @@ class TestProjectJsonschemaValidatedOnlyOnce:
class TestGenericJsonSchemaValidationDeprecation:
"""Ensure that the generic jsonschema validation deprecation can be fired"""
@mock.patch.dict(os.environ, {"DBT_ENV_PRIVATE_RUN_JSONSCHEMA_VALIDATIONS": "True"})
def test_project(self, project, project_root: str) -> None:
# `name` was already required prior to this deprecation, so this deprecation doesn't

View File

@@ -622,7 +622,6 @@ class TestGetRequiredVersion:
class TestDeprecations:
@mock.patch.dict(os.environ, {"DBT_ENV_PRIVATE_RUN_JSONSCHEMA_VALIDATIONS": "True"})
def test_jsonschema_validate(self) -> None:
from dbt.jsonschemas.jsonschemas import jsonschema_validate

View File

@@ -1,6 +1,3 @@
import os
from unittest import mock
from dbt.deprecations import (
CustomKeyInConfigDeprecation,
CustomKeyInObjectDeprecation,
@@ -14,7 +11,6 @@ from dbt_common.events.event_manager_client import add_callback_to_manager
class TestValidateModelConfigNoError:
@mock.patch.dict(os.environ, {"DBT_ENV_PRIVATE_RUN_JSONSCHEMA_VALIDATIONS": "True"})
def test_validate_model_config_no_error(self):
safe_set_invocation_context()
get_invocation_context().uses_adapter("snowflake")
@@ -27,7 +23,6 @@ class TestValidateModelConfigNoError:
validate_model_config(config, "test.yml")
assert len(caught_events) == 0
@mock.patch.dict(os.environ, {"DBT_ENV_PRIVATE_RUN_JSONSCHEMA_VALIDATIONS": "True"})
def test_validate_model_config_error(self):
safe_set_invocation_context()
get_invocation_context().uses_adapter("snowflake")