Compare commits

...

3 Commits

Author SHA1 Message Date
Gerda Shank
bd394acbe4 get info from _get_credentials_from_profile 2024-08-05 11:24:35 -04:00
Gerda Shank
feef873e39 Merge branch 'main' into use_fastjsonschema 2024-07-30 18:05:23 -04:00
Gerda Shank
d580bfd2bc Use fastjsonschema instead of jsonschema for validation 2024-06-01 14:02:24 -04:00
11 changed files with 29 additions and 20 deletions

View File

@@ -0,0 +1,6 @@
kind: Under the Hood
body: Replace jsonschema validation with fastjsonschema
time: 2024-06-01T14:02:18.612839-04:00
custom:
Author: gshank
Issue: "10248"

View File

@@ -146,7 +146,9 @@ class Profile(HasCredentials):
typename = profile.pop("type")
try:
cls = load_plugin(typename)
print(f"--- in _credentials_from_profile. cls: {cls}")
data = cls.translate_aliases(profile)
print(f"--- --- data: {data}")
cls.validate(data)
credentials = cls.from_dict(data)
except (DbtRuntimeError, ValidationError) as e:

View File

@@ -38,7 +38,7 @@ class SelectorConfig(Dict[str, Dict[str, Union[SelectionSpec, bool]]]):
validate_selector_default(selector_file)
selectors = parse_from_selectors_definition(selector_file)
except ValidationError as exc:
yaml_sel_cfg = yaml.dump(exc.instance)
yaml_sel_cfg = yaml.dump(exc.value)
raise DbtSelectorsError(
f"Could not parse selector file data: \n{yaml_sel_cfg}\n"
f"Valid root-level selector definitions: "

View File

@@ -457,12 +457,14 @@ class PatchParser(YamlReader, Generic[NonSourceTarget, Parsed]):
versioned_test_blocks: List[VersionedTestBlock] = []
# get list of 'node' objects
# UnparsedNodeUpdate (TestablePatchParser, models, seeds, snapshots)
# UnparsedNodeUpdate (TestablePatchParser, seeds, snapshots)
# = HasColumnTests, HasTests
# UnparsedAnalysisUpdate (UnparsedAnalysisParser, analyses)
# = HasColumnDocs, HasDocs
# UnparsedMacroUpdate (MacroPatchParser, 'macros')
# = HasDocs
# UnparsedModelUpdate (ModelPatchParser, models)
# = HasColumnTests, HasTests
# correspond to this parser's 'key'
for node in self.get_unparsed_target():
# node_block is a TargetBlock (Macro or Analysis)
@@ -562,7 +564,7 @@ class PatchParser(YamlReader, Generic[NonSourceTarget, Parsed]):
# Raise a validation error if the user has defined both names
def validate_and_rename(data, is_root_project: bool) -> None:
if data.get("tests"):
if "tests" in data and "data_tests" in data:
if data.get("data_tests"):
raise ValidationError(
"Invalid test config: cannot have both 'tests' and 'data_tests' defined"
)

View File

@@ -1,6 +1,6 @@
git+https://github.com/dbt-labs/dbt-adapters.git@main
git+https://github.com/dbt-labs/dbt-adapters.git@main#subdirectory=dbt-tests-adapter
git+https://github.com/dbt-labs/dbt-common.git@main
git+https://github.com/dbt-labs/dbt-common.git@try_fastjsonschema
git+https://github.com/dbt-labs/dbt-postgres.git@main
# black must match what's in .pre-commit-config.yaml to be sure local env matches CI
black==24.3.0

View File

@@ -64,9 +64,7 @@ class TestProjectYamlVersionInvalid:
update_config_file({"version": "invalid"}, "dbt_project.yml")
with pytest.raises(ProjectContractError) as excinfo:
run_dbt()
assert "at path ['version']: 'invalid' is not valid under any of the given schemas" in str(
excinfo.value
)
assert "Invalid value 'invalid'" in str(excinfo.value)
class TestProjectDbtCloudConfig:
@@ -113,9 +111,7 @@ class TestProjectDbtCloudConfigString:
run_dbt()
config = {"name": "test", "profile": "test", "dbt-cloud": "Some string"}
update_config_file(config, "dbt_project.yml")
expected_err = (
"at path ['dbt-cloud']: 'Some string' is not valid under any of the given schemas"
)
expected_err = "Invalid value 'Some string'"
with pytest.raises(ProjectContractError) as excinfo:
run_dbt()
assert expected_err in str(excinfo.value)

View File

@@ -394,9 +394,8 @@ class TestInvalidEnabledConfig:
"my_model.sql": my_model,
}
def test_invalis_config(self, project):
def test_invalid_config(self, project):
with pytest.raises(ValidationError) as exc:
run_dbt(["parse"])
exc_str = " ".join(str(exc.value).split()) # flatten all whitespace
expected_msg = "'True and False' is not of type 'boolean'"
assert expected_msg in exc_str
expected_msg = "Invalid value 'True and False': data.enabled must be boolean"
assert expected_msg in exc.value.msg

View File

@@ -128,5 +128,5 @@ class TestInvalidConfig(ExposureConfigTests):
def test_exposure_config_yaml_level(self, project):
with pytest.raises(ValidationError) as excinfo:
run_dbt(["parse"])
expected_msg = "'True and False' is not of type 'boolean'"
expected_msg = "Invalid value 'True and False': data.enabled must be boolean"
assert expected_msg in str(excinfo.value)

View File

@@ -172,7 +172,7 @@ class TestInvalidMetric(MetricConfigTests):
def test_invalid_config_metric(self, project):
with pytest.raises(ValidationError) as excinfo:
run_dbt(["parse"])
expected_msg = "'True and False' is not of type 'boolean'"
expected_msg = "Invalid value 'True and False': data.enabled must be boolean"
assert expected_msg in str(excinfo.value)

View File

@@ -141,7 +141,11 @@ class TestPostgresInvalidIndex:
def test_invalid_index_configs(self, project):
results, output = run_dbt_and_capture(expect_pass=False)
assert len(results) == 4
assert re.search(r"columns.*is not of type 'array'", output)
assert re.search(r"unique.*is not of type 'boolean'", output)
assert re.search(r"'columns' is a required property", output)
# Could not parse index config: Invalid value 'column_a, column_b': data.columns must be array
assert re.search(r"columns must be array", output)
# Could not parse index config: Invalid value 'yes': data.unique must be boolean
assert re.search(r"unique must be boolean", output)
# Could not parse index config: Invalid value '{'unique': True}': data must contain ['columns'] properties
assert re.search(r"data must contain \['columns'\] properties", output)
# Database Error in model invalid_type (models/invalid_type.sql) / access method "non_existent_type" does not exist
assert re.search(r"Database Error in model invalid_type", output)

View File

@@ -177,5 +177,5 @@ class TestInvalidSourceConfig(SourceConfigTests):
def test_invalid_config_source(self, project):
with pytest.raises(ValidationError) as excinfo:
run_dbt(["parse"])
expected_msg = "'True and False' is not of type 'boolean'"
expected_msg = "Invalid value 'True and False': data.enabled must be boolean"
assert expected_msg in str(excinfo.value)