diff --git a/recce/adapter/dbt_adapter/__init__.py b/recce/adapter/dbt_adapter/__init__.py index d6d74123..d53ce30e 100644 --- a/recce/adapter/dbt_adapter/__init__.py +++ b/recce/adapter/dbt_adapter/__init__.py @@ -632,28 +632,16 @@ def select_nodes(self, select: Optional[str] = None, exclude: Optional[str] = No else: spec = parse_difference(select_list, exclude_list) - manifest = self.manifest.deepcopy() - - for (key, node) in self.previous_state.manifest.nodes.items(): - if key not in manifest.nodes: - manifest.nodes[key] = node - - for (key, node) in self.previous_state.manifest.sources.items(): - if key not in manifest.sources: - manifest.sources[key] = node - - for (key, node) in self.previous_state.manifest.exposures.items(): - if key not in manifest.exposures: - manifest.exposures[key] = node - - for (key, node) in self.previous_state.manifest.metrics.items(): - if key not in manifest.metrics: - manifest.metrics[key] = node - - if hasattr(self.previous_state.manifest, 'semantic_models'): - for (key, node) in self.previous_state.manifest.semantic_models.items(): - if key not in manifest.semantic_models: - manifest.semantic_models[key] = node + manifest = Manifest() + manifest_prev = self.previous_state.manifest + manifest_curr = self.manifest + + manifest.nodes = {**manifest_prev.nodes, **manifest_curr.nodes} + manifest.sources = {**manifest_prev.sources, **manifest_curr.sources} + manifest.exposures = {**manifest_prev.exposures, **manifest_curr.exposures} + manifest.metrics = {**manifest_prev.metrics, **manifest_curr.metrics} + if hasattr(manifest_prev, 'semantic_models'): + manifest.semantic_models = {**manifest_prev.semantic_models, **manifest_curr.semantic_models} compiler = Compiler(self.runtime_config) # disable to print compile states diff --git a/tests/adapter/dbt_adapter/dbt_test_helper.py b/tests/adapter/dbt_adapter/dbt_test_helper.py index 39cf8d2b..d71b8102 100644 --- a/tests/adapter/dbt_adapter/dbt_test_helper.py +++ b/tests/adapter/dbt_adapter/dbt_test_helper.py @@ -41,7 +41,7 @@ def __init__(self): self.adapter.execute(f"CREATE schema IF NOT EXISTS {self.curr_schema}") self.adapter.set_artifacts(self.base_manifest, self.curr_manifest) - def create_model(self, model_name, base_csv=None, curr_csv=None, depends_on=[]): + def create_model(self, model_name, base_csv=None, curr_csv=None, depends_on=[], disabled=False): package_name = "recce_test" # unique_id = f"model.{package_name}.{model_name}" unique_id = model_name @@ -81,7 +81,11 @@ def _add_model_to_manifest(base, raw_code): "nodes": depends_on }, }) - manifest.add_node_nofile(node) + + if disabled: + manifest.add_disabled_nofile(node) + else: + manifest.add_node_nofile(node) return node dbt_adapter = self.adapter diff --git a/tests/adapter/dbt_adapter/test_selector.py b/tests/adapter/dbt_adapter/test_selector.py index 5703d636..ab321091 100644 --- a/tests/adapter/dbt_adapter/test_selector.py +++ b/tests/adapter/dbt_adapter/test_selector.py @@ -99,3 +99,27 @@ def test_select_removed_by_graph(dbt_test_helper): assert len(node_ids) == 2 node_ids = adapter.select_nodes("+customers_3") assert len(node_ids) == 2 + + +def test_select_with_disabled(dbt_test_helper): + csv_data_curr = """ + customer_id,name,age + 1,Alice,30 + 2,Bob,25 + 3,Charlie,35 + """ + + csv_data_base = """ + customer_id,name,age + 1,Alice,35 + 2,Bob,25 + 3,Charlie,35 + """ + + dbt_test_helper.create_model("customers_1", csv_data_base, csv_data_curr) + dbt_test_helper.create_model("customers_2", csv_data_base, csv_data_curr, disabled=True) + adapter: DbtAdapter = dbt_test_helper.context.adapter + + # Test graph operation + node_ids = adapter.select_nodes("customers_1+") + assert len(node_ids) == 1