Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated docs functionality to account for dataclasses refactor #1716

2 changes: 2 additions & 0 deletions core/dbt/contracts/graph/parsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class NodeConfig(
quoting: Dict[str, Any] = field(default_factory=dict)
column_types: Dict[str, Any] = field(default_factory=dict)
tags: Union[List[str], str] = field(default_factory=list_str)
docs: Dict[str, Any] = field(default_factory=dict)

@classmethod
def field_mapping(cls):
Expand Down Expand Up @@ -217,6 +218,7 @@ class ParsedNodeDefaults(ParsedNodeMandatory):
columns: Dict[str, ColumnInfo] = field(default_factory=dict)
patch_path: Optional[str] = None
build_path: Optional[str] = None
docs: Dict[str, Any] = field(default_factory=dict)


@dataclass
Expand Down
8 changes: 7 additions & 1 deletion core/dbt/source_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@

class SourceConfig:
AppendListFields = {'pre-hook', 'post-hook', 'tags'}
ExtendDictFields = {'vars', 'column_types', 'quoting', 'persist_docs'}
ExtendDictFields = {
'vars',
'column_types',
'quoting',
'persist_docs',
'docs'
}
ClobberFields = {
'alias',
'schema',
Expand Down
8 changes: 8 additions & 0 deletions test/unit/test_contracts_graph_compiled.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def test_basic_uncompiled(self):
'schema': 'test_schema',
'alias': 'bar',
'tags': [],
'docs':{},
'config': {
'column_types': {},
'enabled': True,
Expand All @@ -42,6 +43,7 @@ def test_basic_uncompiled(self):
'pre-hook': [],
'quoting': {},
'tags': [],
'docs':{},
'vars': {},
},
'docrefs': [],
Expand Down Expand Up @@ -115,6 +117,7 @@ def test_basic_compiled(self):
'schema': 'test_schema',
'alias': 'bar',
'tags': [],
'docs':{},
'config': {
'column_types': {},
'enabled': True,
Expand All @@ -124,6 +127,7 @@ def test_basic_compiled(self):
'pre-hook': [],
'quoting': {},
'tags': [],
'docs': {},
'vars': {},
},
'docrefs': [],
Expand Down Expand Up @@ -225,6 +229,7 @@ def test_basic_uncompiled(self):
'schema': 'test_schema',
'alias': 'bar',
'tags': [],
'docs': {},
'config': {
'column_types': {},
'enabled': True,
Expand All @@ -234,6 +239,7 @@ def test_basic_uncompiled(self):
'pre-hook': [],
'quoting': {},
'tags': [],
'docs': {},
'vars': {},
'severity': 'error',
},
Expand Down Expand Up @@ -308,6 +314,7 @@ def test_basic_compiled(self):
'schema': 'test_schema',
'alias': 'bar',
'tags': [],
'docs':{},
'config': {
'column_types': {},
'enabled': True,
Expand All @@ -317,6 +324,7 @@ def test_basic_compiled(self):
'pre-hook': [],
'quoting': {},
'tags': [],
'docs': {},
'vars': {},
'severity': 'warn',
},
Expand Down
24 changes: 24 additions & 0 deletions test/unit/test_contracts_graph_parsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def test_basics(self):
'pre-hook': [],
'quoting': {},
'tags': [],
'docs': {},
'vars': {},
}
cfg = self.ContractType()
Expand All @@ -42,6 +43,7 @@ def test_populated(self):
'pre-hook': [],
'quoting': {},
'tags': [],
'docs': {},
'vars': {},
'extra': 'even more',
}
Expand Down Expand Up @@ -78,6 +80,7 @@ def test_ok(self):
'schema': 'test_schema',
'alias': 'bar',
'tags': [],
'docs':{},
'config': {
'column_types': {},
'enabled': True,
Expand All @@ -87,6 +90,7 @@ def test_ok(self):
'pre-hook': [],
'quoting': {},
'tags': [],
'docs':{},
'vars': {},
},
'docrefs': [],
Expand Down Expand Up @@ -154,6 +158,7 @@ def test_complex(self):
'schema': 'test_schema',
'alias': 'bar',
'tags': ['tag'],
'docs':{},
'config': {
'column_types': {'a': 'text'},
'enabled': True,
Expand All @@ -163,6 +168,7 @@ def test_complex(self):
'pre-hook': [],
'quoting': {},
'tags': [],
'docs':{},
'vars': {'foo': 100},
},
'docrefs': [],
Expand Down Expand Up @@ -324,6 +330,7 @@ def test_patch_ok(self):
'schema': 'test_schema',
'alias': 'bar',
'tags': [],
'docs':{},
'config': {
'column_types': {},
'enabled': True,
Expand All @@ -333,6 +340,7 @@ def test_patch_ok(self):
'pre-hook': [],
'quoting': {},
'tags': [],
'docs':{},
'vars': {},
},
'patch_path': '/path/to/schema.yml',
Expand Down Expand Up @@ -429,6 +437,7 @@ def test_ok(self):
'schema': 'test_schema',
'alias': 'bar',
'tags': [],
'docs':{},
'config': {
'column_types': {},
'enabled': True,
Expand All @@ -439,6 +448,7 @@ def test_ok(self):
'quoting': {},
'tags': [],
'vars': {},
'docs':{},
},
'docrefs': [],
'columns': {},
Expand Down Expand Up @@ -504,6 +514,7 @@ def test_complex(self):
'schema': 'test_schema',
'alias': 'bar',
'tags': ['tag'],
'docs':{},
'config': {
'column_types': {'a': 'text'},
'enabled': True,
Expand All @@ -513,6 +524,7 @@ def test_complex(self):
'pre-hook': [],
'quoting': {},
'tags': [],
'docs':{},
'vars': {},
},
'docrefs': [],
Expand Down Expand Up @@ -611,6 +623,7 @@ def test_ok(self):
'schema': 'test_schema',
'alias': 'bar',
'tags': [],
'docs':{},
'config': {
'column_types': {},
'enabled': True,
Expand All @@ -620,6 +633,7 @@ def test_ok(self):
'pre-hook': [],
'quoting': {},
'tags': [],
'docs':{},
'vars': {},
'severity': 'error',
},
Expand Down Expand Up @@ -688,6 +702,7 @@ def test_complex(self):
'schema': 'test_schema',
'alias': 'bar',
'tags': ['tag'],
'docs':{},
'config': {
'column_types': {'a': 'text'},
'enabled': True,
Expand All @@ -698,6 +713,7 @@ def test_complex(self):
'quoting': {},
'tags': [],
'vars': {},
'docs':{},
'severity': 'WARN',
'extra_key': 'extra value'
},
Expand Down Expand Up @@ -863,6 +879,7 @@ def test_basics(self):
'pre-hook': [],
'quoting': {},
'tags': [],
'docs':{},
'vars': {},
'unique_key': 'id',
'strategy': 'timestamp',
Expand Down Expand Up @@ -890,6 +907,7 @@ def test_populated(self):
'pre-hook': [],
'quoting': {},
'tags': [],
'docs':{},
'vars': {},
'target_database': 'some_snapshot_db',
'target_schema': 'some_snapshot_schema',
Expand Down Expand Up @@ -964,6 +982,7 @@ def test_basics(self):
'pre-hook': [],
'quoting': {},
'tags': [],
'docs':{},
'vars': {},
'target_database': 'some_snapshot_db',
'target_schema': 'some_snapshot_schema',
Expand Down Expand Up @@ -991,6 +1010,7 @@ def test_populated(self):
'pre-hook': [],
'quoting': {},
'tags': [],
'docs':{},
'vars': {},
'target_database': 'some_snapshot_db',
'target_schema': 'some_snapshot_schema',
Expand Down Expand Up @@ -1093,6 +1113,7 @@ def test_timestamp_ok(self):
'schema': 'test_schema',
'alias': 'bar',
'tags': [],
'docs': {},
'config': {
'column_types': {},
'enabled': True,
Expand All @@ -1102,6 +1123,7 @@ def test_timestamp_ok(self):
'pre-hook': [],
'quoting': {},
'tags': [],
'docs':{},
'vars': {},
'target_database': 'some_snapshot_db',
'target_schema': 'some_snapshot_schema',
Expand Down Expand Up @@ -1198,6 +1220,7 @@ def test_check_ok(self):
'schema': 'test_schema',
'alias': 'bar',
'tags': [],
'docs':{},
'config': {
'column_types': {},
'enabled': True,
Expand All @@ -1207,6 +1230,7 @@ def test_check_ok(self):
'pre-hook': [],
'quoting': {},
'tags': [],
'docs':{},
'vars': {},
'target_database': 'some_snapshot_db',
'target_schema': 'some_snapshot_schema',
Expand Down
1 change: 1 addition & 0 deletions test/unit/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
'depends_on', 'database', 'schema', 'name', 'resource_type',
'package_name', 'root_path', 'path', 'original_file_path', 'raw_sql',
'docrefs', 'description', 'columns', 'fqn', 'build_path', 'patch_path',
'docs'
})

REQUIRED_COMPILED_NODE_KEYS = frozenset(REQUIRED_PARSED_NODE_KEYS | {
Expand Down
7 changes: 4 additions & 3 deletions test/unit/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def test_basic(self):
package_name='snowplow',
original_file_path=normalize('models/nested/model_1.sql'),
root_path=get_abs_os_path('./dbt_modules/snowplow'),
config=NodeConfig(materialized='table'),
config=NodeConfig(materialized='table',docs={}),
path=normalize('nested/model_1.sql'),
raw_sql=raw_sql,
)
Expand Down Expand Up @@ -461,6 +461,7 @@ def test_single_block(self):
updated_at='last_update',
target_database='dbt',
target_schema='analytics',
docs={},
unique_key='id',
materialized='snapshot',
),
Expand Down Expand Up @@ -613,7 +614,7 @@ def test_basic(self):
original_file_path=normalize('tests/test_1.sql'),
root_path=get_abs_os_path('./dbt_modules/snowplow'),
refs=[['blah']],
config=TestConfig(severity='ERROR'),
config=TestConfig(severity='ERROR',docs={}),
tags=['data'],
path=normalize('data_test/test_1.sql'),
raw_sql=raw_sql,
Expand Down Expand Up @@ -655,7 +656,7 @@ def test_basic(self):
original_file_path=normalize('analyses/nested/analysis_1.sql'),
root_path=get_abs_os_path('./dbt_modules/snowplow'),
depends_on=DependsOn(),
config=NodeConfig(),
config=NodeConfig(docs={}),
path=normalize('analysis/nested/analysis_1.sql'),
raw_sql=raw_sql,
)
Expand Down
2 changes: 2 additions & 0 deletions test/unit/test_source_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def test__source_config_single_call(self):
'sort': 'my sort key',
'tags': [],
'vars': {'a': 1, 'b': 2},
'docs':{},
}
self.assertEqual(cfg.config, expect)

Expand Down Expand Up @@ -117,6 +118,7 @@ def test__source_config_multiple_calls(self):
'sort': 'my sort key',
'tags': [],
'vars': {'a': 4, 'b': 2, 'c': 3},
'docs':{},
}
self.assertEqual(cfg.config, expect)

Expand Down