Skip to content

Commit

Permalink
Add code in parser/partial.py. Breaking test for meta.
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank committed Dec 5, 2024
1 parent 7b5aad1 commit e32fef5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
19 changes: 19 additions & 0 deletions core/dbt/parser/partial.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ def handle_change(key: str, delete: Callable):
handle_change("semantic_models", self.delete_schema_semantic_model)
handle_change("unit_tests", self.delete_schema_unit_test)
handle_change("saved_queries", self.delete_schema_saved_query)
handle_change("data_tests", self.delete_schema_data_test_patch)

def _handle_element_change(
self, schema_file, saved_yaml_dict, new_yaml_dict, env_var_changes, dict_key: str, delete
Expand Down Expand Up @@ -919,6 +920,24 @@ def delete_schema_macro_patch(self, schema_file, macro):
self.saved_files[macro_file_id] = deepcopy(self.new_files[macro_file_id])
self.add_to_pp_files(self.saved_files[macro_file_id])

def delete_schema_data_test_patch(self, schema_file, data_test):
print(f"--- in delete_schema_data_test_patch")
data_test_unique_id = None
for unique_id in schema_file.node_patches:
if not unique_id.startswith("test"):
continue
parts = unique_id.split(".")
elem_name = parts[2]
if elem_name == data_test["name"]:
data_test_unique_id = unique_id
break
if data_test_unique_id and data_test_unique_id in self.saved_manifest.nodes:
singular_data_test = self.saved_manifest.nodes.pop(data_test_unique_id)
file_id = singular_data_test.file_id
if file_id in self.new_files:
self.saved_files[file_id] = deepcopy(self.new_files[file_id])
self.add_to_pp_files(self.saved_files[file_id])

# exposures are created only from schema files, so just delete
# the exposure or the disabled exposure.
def delete_schema_exposure(self, schema_file, exposure_dict):
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/data_test_patch/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
config:
error_if: ">10"
meta:
some_key: some_val
some_key: another_val
"""

tests__doc_block_md = """
Expand Down
17 changes: 10 additions & 7 deletions tests/functional/data_test_patch/test_singular_test_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from dbt.tests.util import get_artifact, run_dbt, run_dbt_and_capture, write_file
from dbt.tests.util import get_manifest, run_dbt, run_dbt_and_capture, write_file
from tests.functional.data_test_patch.fixtures import (
tests__doc_block_md,
tests__invalid_name_schema_yml,
Expand All @@ -24,19 +24,22 @@ def tests(self):

def test_compile(self, project):
run_dbt(["compile"])
manifest = get_artifact(project.project_root, "target", "manifest.json")
assert len(manifest["nodes"]) == 1
manifest = get_manifest(project.project_root)
assert len(manifest.nodes) == 1

my_singular_test_node = manifest["nodes"]["test.test.my_singular_test"]
assert my_singular_test_node["description"] == "Some docs from a doc block"
assert my_singular_test_node["config"]["error_if"] == ">10"
assert my_singular_test_node["config"]["meta"] == {"some_key": "some_val"}
my_singular_test_node = manifest.nodes["test.test.my_singular_test"]
assert my_singular_test_node.description == "Some docs from a doc block"
assert my_singular_test_node.config.error_if == ">10"
assert my_singular_test_node.config.meta == {"some_key": "some_val"}
assert my_singular_test_node.meta == {"some_key": "some_val"}

# partial parsing test
write_file(tests__schema_2_yml, project.project_root, "tests", "schema.yml")
manifest = run_dbt(["parse"])
test_node = manifest.nodes["test.test.my_singular_test"]
assert test_node.description == "My singular test description"
print(f"--- config.meta: {test_node.config.meta}")
print(f"--- node.meta: {test_node.meta}")


class TestPatchSingularTestInvalidName:
Expand Down

0 comments on commit e32fef5

Please sign in to comment.