Skip to content

Commit

Permalink
Merge pull request #2440 from fishtown-analytics/fix/empty-persist-docs
Browse files Browse the repository at this point in the history
Fix empty SQL in persist docs (#2439)
  • Loading branch information
beckjake authored May 13, 2020
2 parents 7b374a4 + 0535464 commit 457cbbd
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 54 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

## dbt 0.17.0 (Release TBD)


### Fixes
- When no columns are documented and persist_docs.columns is True, skip creating comments instead of failing with errors ([#2439](https:/fishtown-analytics/dbt/issues/2439), [#2440](https:/fishtown-analytics/dbt/pull/2440))


## dbt 0.17.0rc1 (May 12, 2020)

### Breaking changes
Expand Down
4 changes: 2 additions & 2 deletions core/dbt/include/global_project/macros/adapters/common.sql
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@
{% endmacro %}

{% macro default__persist_docs(relation, model, for_relation, for_columns) -%}
{% if for_relation and config.persist_relation_docs() %}
{% if for_relation and config.persist_relation_docs() and model.description %}
{% do run_query(alter_relation_comment(relation, model.description)) %}
{% endif %}

{% if for_columns and config.persist_column_docs() %}
{% if for_columns and config.persist_column_docs() and model.columns %}
{% do run_query(alter_column_comment(relation, model.columns)) %}
{% endif %}
{% endmacro %}
Expand Down
2 changes: 1 addition & 1 deletion plugins/bigquery/dbt/include/bigquery/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@

{#-- relation-level macro is not implemented. This is handled in the CTAs statement #}
{% macro bigquery__persist_docs(relation, model, for_relation, for_columns) -%}
{% if for_columns and config.persist_column_docs() %}
{% if for_columns and config.persist_column_docs() and model.columns %}
{% do alter_column_comment(relation, model.columns) %}
{% endif %}
{% endmacro %}
Expand Down
4 changes: 2 additions & 2 deletions plugins/redshift/dbt/include/redshift/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@


{% macro redshift__persist_docs(relation, model, for_relation, for_columns) -%}
{% if for_relation and config.persist_relation_docs() %}
{% if for_relation and config.persist_relation_docs() and model.description %}
{% do run_query(alter_relation_comment(relation, model.description)) %}
{% endif %}

{# Override: do not set column comments for LBVs #}
{% set is_lbv = config.get('materialized') == 'view' and config.get('bind') == false %}
{% if for_columns and config.persist_column_docs() and not is_lbv %}
{% if for_columns and config.persist_column_docs() and model.columns and not is_lbv %}
{% do run_query(alter_column_comment(relation, model.columns)) %}
{% endif %}
{% endmacro %}
Expand Down

This file was deleted.

21 changes: 0 additions & 21 deletions test/integration/059_persist_docs_test/sf_models/schema.yml

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select 1 as id, 'Alice' as name
13 changes: 8 additions & 5 deletions test/integration/060_persist_docs_tests/test_persist_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,16 @@ def run_has_comments_pglike(self):
with open('target/catalog.json') as fp:
catalog_data = json.load(fp)
assert 'nodes' in catalog_data
assert len(catalog_data['nodes']) == 2
assert len(catalog_data['nodes']) == 3
table_node = catalog_data['nodes']['model.test.table_model']
view_node = self._assert_has_table_comments(table_node)

view_node = catalog_data['nodes']['model.test.view_model']
self._assert_has_view_comments(view_node)

no_docs_node = catalog_data['nodes']['model.test.no_docs_model']
self._assert_has_view_comments(no_docs_node, False, False)

@use_profile('postgres')
def test_postgres_comments(self):
self.run_has_comments_pglike()
Expand Down Expand Up @@ -116,13 +119,16 @@ def test_redshift_late_binding_view(self):
with open('target/catalog.json') as fp:
catalog_data = json.load(fp)
assert 'nodes' in catalog_data
assert len(catalog_data['nodes']) == 2
assert len(catalog_data['nodes']) == 3
table_node = catalog_data['nodes']['model.test.table_model']
view_node = self._assert_has_table_comments(table_node)

view_node = catalog_data['nodes']['model.test.view_model']
self._assert_has_view_comments(view_node, False, False)

no_docs_node = catalog_data['nodes']['model.test.no_docs_model']
self._assert_has_view_comments(no_docs_node, False, False)


class TestPersistDocsSimple(BasePersistDocsTest):
@property
Expand All @@ -135,9 +141,6 @@ def project_config(self):
"relation": True,
"columns": True,
},
'view_model': {
'bind': False,
}
}
}
}
Expand Down

0 comments on commit 457cbbd

Please sign in to comment.