Skip to content

Commit

Permalink
Fix #9119: Get sources working again in dbt docs generate (#9159)
Browse files Browse the repository at this point in the history
  • Loading branch information
aranke committed Nov 28, 2023
1 parent 32fde75 commit c836b75
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20231128-155225.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: 'Get sources working again in dbt docs generate'
time: 2023-11-28T15:52:25.738256Z
custom:
Author: aranke
Issue: "9119"
6 changes: 6 additions & 0 deletions core/dbt/task/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ def run(self) -> CatalogArtifact:
if self.job_queue is not None:
selected_node_ids = self.job_queue.get_selected_nodes()
selected_nodes = self._get_nodes_from_ids(self.manifest, selected_node_ids)

source_ids = self._get_nodes_from_ids(
self.manifest, self.manifest.sources.keys()
)
selected_nodes.extend(source_ids)

relations = {
adapter.Relation.create_from(adapter.config, node_id)
for node_id in selected_nodes
Expand Down
69 changes: 67 additions & 2 deletions tests/functional/docs/test_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,47 @@

from dbt.tests.util import run_dbt, get_manifest

sample_seed = """sample_num,sample_bool
1,true
2,false
3,true
"""

class TestGenerate:
second_seed = """sample_num,sample_bool
4,true
5,false
6,true
"""

sample_config = """
sources:
- name: my_seed
schema: "{{ target.schema }}"
tables:
- name: sample_seed
- name: second_seed
- name: fake_seed
"""


class TestBaseGenerate:
@pytest.fixture(scope="class")
def models(self):
return {"my_model.sql": "select 1 as fun", "alt_model.sql": "select 1 as notfun"}
return {
"my_model.sql": "select 1 as fun",
"alt_model.sql": "select 1 as notfun",
"sample_config.yml": sample_config,
}

@pytest.fixture(scope="class")
def seeds(self):
return {
"sample_seed.csv": sample_seed,
"second_seed.csv": sample_seed,
}


class TestGenerateManifestNotCompiled(TestBaseGenerate):
def test_manifest_not_compiled(self, project):
run_dbt(["docs", "generate", "--no-compile"])
# manifest.json is written out in parsing now, but it
Expand All @@ -17,19 +52,49 @@ def test_manifest_not_compiled(self, project):
assert model_id in manifest.nodes
assert manifest.nodes[model_id].compiled is False


class TestGenerateEmptyCatalog(TestBaseGenerate):
def test_generate_empty_catalog(self, project):
catalog = run_dbt(["docs", "generate", "--empty-catalog"])
assert catalog.nodes == {}, "nodes should be empty"
assert catalog.sources == {}, "sources should be empty"
assert catalog.errors is None, "errors should be null"


class TestGenerateSelectLimitsCatalog(TestBaseGenerate):
def test_select_limits_catalog(self, project):
run_dbt(["run"])
catalog = run_dbt(["docs", "generate", "--select", "my_model"])
assert len(catalog.nodes) == 1
assert "model.test.my_model" in catalog.nodes


class TestGenerateSelectLimitsNoMatch(TestBaseGenerate):
def test_select_limits_no_match(self, project):
run_dbt(["run"])
catalog = run_dbt(["docs", "generate", "--select", "my_missing_model"])
assert len(catalog.nodes) == 0


class TestGenerateCatalogWithSources(TestBaseGenerate):
def test_catalog_with_sources(self, project):
run_dbt(["build"])
catalog = run_dbt(["docs", "generate"])

# 2 seeds + 2 models
assert len(catalog.nodes) == 4
# 2 sources (only ones that exist)
assert len(catalog.sources) == 2


class TestGenerateSelectSource(TestBaseGenerate):
def test_select_source(self, project):
run_dbt(["build"])
catalog = run_dbt(["docs", "generate", "--select", "source:test.my_seed.sample_seed"])

# 2 seeds
# TODO: Filtering doesn't work for seeds
assert len(catalog.nodes) == 2
# 2 sources
# TODO: Filtering doesn't work for sources
assert len(catalog.sources) == 2

0 comments on commit c836b75

Please sign in to comment.