Skip to content

Commit

Permalink
TestGenerateCatalogWithExternalNodes (#9456) (#9483)
Browse files Browse the repository at this point in the history
* TestGenerateCatalogWithExternalNodes (#9456)

(cherry picked from commit 06e55bb)

* Flip logic in `packages_for_node` to remove error case

By flipping the logic from `not in` to `in` we can drop the exception
and instead default to the model runtime config when the package isn't
found. We're still trying to grok if there will be any fallout from this.
The tests all pass, but that doesn't guarantee nothing bad will happen.

---------

Co-authored-by: Quigley Malcolm <quigley.malcolm@dbtlabs.com>
  • Loading branch information
MichelleArk and QMalcolm authored Jan 31, 2024
1 parent 1391363 commit cfbba81
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Fixes-20240125-182243.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Fixes
body: Add TestGenerateCatalogWithExternalNodes, include empty nodes in node selection
during docs generate
time: 2024-01-25T18:22:43.253228-05:00
custom:
Author: michelleark
Issue: "9456"
7 changes: 2 additions & 5 deletions core/dbt/context/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
MetricArgsError,
MissingConfigError,
OperationsCannotRefEphemeralNodesError,
PackageNotInDepsError,
ParsingError,
RefBadContextError,
RefArgsError,
Expand Down Expand Up @@ -638,10 +637,8 @@ def packages_for_node(self) -> Iterable[Project]:
package_name = self._node.package_name

if package_name != self._config.project_name:
if package_name not in dependencies:
# I don't think this is actually reachable
raise PackageNotInDepsError(package_name, node=self._node)
yield dependencies[package_name]
if package_name in dependencies:
yield dependencies[package_name]
yield self._config

def _generate_merged(self) -> Mapping[str, Any]:
Expand Down
1 change: 1 addition & 0 deletions core/dbt/task/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ def get_node_selector(self) -> ResourceTypeSelector:
manifest=self.manifest,
previous_state=self.previous_state,
resource_types=NodeType.executable(),
include_empty_nodes=True,
)

def get_catalog_results(
Expand Down
24 changes: 24 additions & 0 deletions tests/functional/docs/test_generate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest
from unittest import mock

from dbt.plugins.manifest import PluginNodes, ModelNodeArgs
from dbt.tests.util import run_dbt, get_manifest

sample_seed = """sample_num,sample_bool
Expand Down Expand Up @@ -95,6 +97,28 @@ def test_catalog_with_sources(self, project):
assert len(catalog.sources) == 2


class TestGenerateCatalogWithExternalNodes(TestBaseGenerate):
@mock.patch("dbt.plugins.get_plugin_manager")
def test_catalog_with_sources(self, get_plugin_manager, project):
project.run_sql("create table {}.external_model (id int)".format(project.test_schema))

run_dbt(["build"])

external_nodes = PluginNodes()
external_model_node = ModelNodeArgs(
name="external_model",
package_name="external_package",
identifier="external_model",
schema=project.test_schema,
database="dbt",
)
external_nodes.add_model(external_model_node)
get_plugin_manager.return_value.get_nodes.return_value = external_nodes
catalog = run_dbt(["docs", "generate"])

assert "model.external_package.external_model" in catalog.nodes


class TestGenerateSelectSource(TestBaseGenerate):
@pytest.fixture(scope="class")
def seeds(self):
Expand Down

0 comments on commit cfbba81

Please sign in to comment.