mirror of
https://github.com/dbt-labs/dbt-core
synced 2025-12-17 19:31:34 +00:00
Fix partial parsing bug with singular tests (#12224)
This commit is contained in:
6
.changes/unreleased/Fixes-20251128-102129.yaml
Normal file
6
.changes/unreleased/Fixes-20251128-102129.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
kind: Fixes
|
||||
body: Fix bug in partial parsing when updating a model with a schema file that is referenced by a singular test
|
||||
time: 2025-11-28T10:21:29.911147Z
|
||||
custom:
|
||||
Author: mattogburke
|
||||
Issue: "12223"
|
||||
@@ -11,7 +11,13 @@ from dbt.contracts.files import (
|
||||
parse_file_type_to_parser,
|
||||
)
|
||||
from dbt.contracts.graph.manifest import Manifest
|
||||
from dbt.contracts.graph.nodes import AnalysisNode, ModelNode, SeedNode, SnapshotNode
|
||||
from dbt.contracts.graph.nodes import (
|
||||
AnalysisNode,
|
||||
GenericTestNode,
|
||||
ModelNode,
|
||||
SeedNode,
|
||||
SnapshotNode,
|
||||
)
|
||||
from dbt.events.types import PartialParsingEnabled, PartialParsingFile
|
||||
from dbt.node_types import NodeType
|
||||
from dbt_common.context import get_invocation_context
|
||||
@@ -970,7 +976,7 @@ class PartialParsing:
|
||||
for child_id in self.saved_manifest.child_map[unique_id]:
|
||||
if child_id.startswith("test") and child_id in self.saved_manifest.nodes:
|
||||
child_test = self.saved_manifest.nodes[child_id]
|
||||
if child_test.attached_node:
|
||||
if isinstance(child_test, GenericTestNode) and child_test.attached_node:
|
||||
if child_test.attached_node in self.saved_manifest.nodes:
|
||||
attached_node = self.saved_manifest.nodes[child_test.attached_node]
|
||||
self.update_in_saved(attached_node.file_id)
|
||||
|
||||
@@ -553,6 +553,12 @@ select * from renamed
|
||||
|
||||
"""
|
||||
|
||||
customers_yml = """
|
||||
models:
|
||||
- name: customers
|
||||
description: "This table contains customer data"
|
||||
"""
|
||||
|
||||
model_four2_sql = """
|
||||
select fun from {{ ref('model_one') }}
|
||||
|
||||
@@ -689,6 +695,17 @@ select 1 as id, 101 as user_id, 'pending' as status
|
||||
|
||||
"""
|
||||
|
||||
orders_sql_modified = """
|
||||
select 1 as id, 101 as user_id, 'completed' as status
|
||||
|
||||
"""
|
||||
|
||||
orders_singular_test_sql = """
|
||||
select * from {{ ref('orders') }}
|
||||
where status = 'invalid'
|
||||
|
||||
"""
|
||||
|
||||
orders_downstream_sql = """
|
||||
select * from {{ ref('orders') }}
|
||||
|
||||
|
||||
@@ -65,7 +65,9 @@ from tests.functional.partial_parsing.fixtures import (
|
||||
my_macro2_sql,
|
||||
my_macro_sql,
|
||||
my_test_sql,
|
||||
orders_singular_test_sql,
|
||||
orders_sql,
|
||||
orders_sql_modified,
|
||||
raw_customers_csv,
|
||||
ref_override2_sql,
|
||||
ref_override_sql,
|
||||
@@ -669,7 +671,7 @@ class TestSnapshots:
|
||||
assert len(results) == 1
|
||||
|
||||
|
||||
class TestTests:
|
||||
class TestGenericTests:
|
||||
@pytest.fixture(scope="class")
|
||||
def models(self):
|
||||
return {
|
||||
@@ -723,6 +725,39 @@ class TestTests:
|
||||
assert expected_nodes == list(manifest.nodes.keys())
|
||||
|
||||
|
||||
class TestSingularTests:
|
||||
@pytest.fixture(scope="class")
|
||||
def models(self):
|
||||
return {
|
||||
"orders.sql": orders_sql,
|
||||
"schema.yml": generic_schema_yml,
|
||||
}
|
||||
|
||||
@pytest.fixture(scope="class")
|
||||
def tests(self):
|
||||
# Make sure "generic" directory is created
|
||||
return {"generic": {"readme.md": ""}}
|
||||
|
||||
def test_pp_singular_tests(self, project):
|
||||
|
||||
# initial run
|
||||
results = run_dbt()
|
||||
assert len(results) == 1
|
||||
manifest = get_manifest(project.project_root)
|
||||
expected_nodes = ["model.test.orders", "test.test.unique_orders_id.1360ecc70e"]
|
||||
assert expected_nodes == list(manifest.nodes.keys())
|
||||
|
||||
# add singular test in test-path
|
||||
write_file(orders_singular_test_sql, project.project_root, "tests", "singular_test.sql")
|
||||
results = run_dbt(["--partial-parse", "run"])
|
||||
assert len(results) == 1
|
||||
|
||||
# modify model being tested by singular test
|
||||
write_file(orders_sql_modified, project.project_root, "models", "orders.sql")
|
||||
results = run_dbt(["--partial-parse", "run"])
|
||||
assert len(results) == 1
|
||||
|
||||
|
||||
class TestExternalModels:
|
||||
@pytest.fixture(scope="class")
|
||||
def external_model_node(self):
|
||||
|
||||
Reference in New Issue
Block a user