Skip to content

Commit 203e331

Browse files
[Backport 1.6.latest] support doc blocks on versioned models (#8784)
* support doc blocks (#8771) (cherry picked from commit df791f7) * pin dev requirement --------- Co-authored-by: Emily Rockman <emily.rockman@dbtlabs.com>
1 parent 0a78a96 commit 203e331

File tree

5 files changed

+90
-2
lines changed

5 files changed

+90
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Fixes
2+
body: Support docs blocks on versioned model column descriptions
3+
time: 2023-10-04T14:41:48.843486-05:00
4+
custom:
5+
Author: emmyoop
6+
Issue: "8540"

core/dbt/parser/manifest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,10 +1115,12 @@ def update_semantic_model(self, semantic_model) -> None:
11151115
database=refd_node.database,
11161116
)
11171117

1118-
# nodes: node and column descriptions
1118+
# nodes: node and column descriptions, version columns descriptions
11191119
# sources: source and table descriptions, column descriptions
11201120
# macros: macro argument descriptions
11211121
# exposures: exposure descriptions
1122+
# metrics: metric descriptions
1123+
# semantic_models: semantic model descriptions
11221124
def process_docs(self, config: RuntimeConfig):
11231125
for node in self.manifest.nodes.values():
11241126
if node.created_at < self.started_at:

core/dbt/parser/schema_renderer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,18 @@ def _is_norender_key(self, keypath: Keypath) -> bool:
3434
Return True if it's tests or description - those aren't rendered now
3535
because they're rendered later in parse_generic_tests or process_docs.
3636
"""
37+
# top level descriptions and tests
3738
if len(keypath) >= 1 and keypath[0] in ("tests", "description"):
3839
return True
3940

41+
# columns descriptions and tests
4042
if len(keypath) == 2 and keypath[1] in ("tests", "description"):
4143
return True
4244

45+
# versions
46+
if len(keypath) == 5 and keypath[4] == "description":
47+
return True
48+
4349
if (
4450
len(keypath) >= 3
4551
and keypath[0] in ("columns", "dimensions", "measures", "entities")

dev-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ types-mock
3030
types-protobuf
3131
types-python-dateutil
3232
types-pytz
33-
types-requests
33+
types-requests < 2.31.0 # types-requests 2.31.0.8 requires urllib3>=2, but we pin urllib3 ~= 1.0 because of openssl requirement for requests
3434
types-setuptools
3535
wheel
3636
mocker
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import pytest
2+
3+
from dbt.tests.util import run_dbt
4+
5+
model_1 = """
6+
select 1 as id, 'joe' as first_name
7+
"""
8+
9+
model_versioned = """
10+
select 1 as id, 'joe' as first_name
11+
"""
12+
13+
docs_md = """
14+
{% docs model_description %}
15+
unversioned model
16+
{% enddocs %}
17+
18+
{% docs column_id_doc %}
19+
column id for some thing
20+
{% enddocs %}
21+
22+
{% docs versioned_model_description %}
23+
versioned model
24+
{% enddocs %}
25+
26+
"""
27+
28+
schema_yml = """
29+
models:
30+
- name: model_1
31+
description: '{{ doc("model_description") }}'
32+
columns:
33+
- name: id
34+
description: '{{ doc("column_id_doc") }}'
35+
36+
- name: model_versioned
37+
description: '{{ doc("versioned_model_description") }}'
38+
latest_version: 1
39+
versions:
40+
- v: 1
41+
config:
42+
alias: my_alias
43+
columns:
44+
- name: id
45+
description: '{{ doc("column_id_doc") }}'
46+
- name: first_name
47+
description: 'plain text'
48+
- v: 2
49+
columns:
50+
- name: other_id
51+
"""
52+
53+
54+
class TestVersionedModelDocsBlock:
55+
@pytest.fixture(scope="class")
56+
def models(self):
57+
return {
58+
"model_1.sql": model_1,
59+
"model_versioned.sql": model_versioned,
60+
"schema.yml": schema_yml,
61+
"docs.md": docs_md,
62+
}
63+
64+
def test_versioned_doc_ref(self, project):
65+
manifest = run_dbt(["parse"])
66+
model_1 = manifest.nodes["model.test.model_1"]
67+
model_v1 = manifest.nodes["model.test.model_versioned.v1"]
68+
69+
assert model_1.description == "unversioned model"
70+
assert model_v1.description == "versioned model"
71+
72+
assert model_1.columns["id"].description == "column id for some thing"
73+
assert model_v1.columns["id"].description == "column id for some thing"
74+
assert model_v1.columns["first_name"].description == "plain text"

0 commit comments

Comments
 (0)