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

Only set the comment when persist_docs.relation is set #344

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/unreleased/Fixes-20230810-233738.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Fixes
body: Only set the comment when persist_docs.relation is set
time: 2023-08-10T23:37:38.828664+02:00
custom:
Author: Fokko
Issue: "317"
PR: "343"
8 changes: 6 additions & 2 deletions dbt/include/trino/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@
{%- endmacro -%}

{% macro comment(comment) %}
{%- if comment is not none and comment|length > 0 -%}
comment '{{ comment | replace("'", "''") }}'
{%- set persist_docs = model['config'].get('persist_docs') -%}
{%- if persist_docs -%}
{%- set persist_relation = persist_docs.get('relation') -%}
{%- if persist_relation and comment is not none and comment|length > 0 -%}
comment '{{ comment | replace("'", "''") }}'
{%- endif -%}
{%- endif -%}
{%- endmacro -%}

Expand Down
60 changes: 59 additions & 1 deletion tests/functional/adapter/persist_docs/test_persist_docs.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import pytest
from dbt.tests.adapter.persist_docs.test_persist_docs import (
BasePersistDocs,
BasePersistDocsBase,
BasePersistDocsColumnMissing,
BasePersistDocsCommentOnQuotedColumn,
)
from dbt.tests.util import run_dbt
from dbt.tests.util import run_dbt, run_sql_with_adapter

from tests.functional.adapter.persist_docs.fixtures import (
incremental_model,
Expand Down Expand Up @@ -142,3 +143,60 @@ class TestPersistDocsColumnMissing(BasePersistDocsColumnMissing):

class TestPersistDocsCommentOnQuotedColumn(BasePersistDocsCommentOnQuotedColumn):
pass


class BasePersistDocsDisabled(BasePersistDocsBase):
def test_persist_docs_disabled(self, project):
sql = f"""select * from system.metadata.table_comments
where catalog_name = '{project.database}'
and schema_name = '{project.test_schema}'
and table_name = 'table_model'
and comment is not null
"""
result = run_sql_with_adapter(project.adapter, sql, fetch="all")
assert len(result) == 0


class TestPersistDocsDisabledByDefault(BasePersistDocsDisabled):
"""
Without providing `persist_docs` config, table comments shouldn't be added by default.
"""

pass


class TestPersistDocsRelationSetToFalse(BasePersistDocsDisabled):
"""
With `persist_docs.relation` config set to False, table comments shouldn't be added.
"""

@pytest.fixture(scope="class")
def project_config_update(self):
return {
"models": {
"test": {
"+persist_docs": {
"relation": False,
"columns": True,
},
}
}
}


class TestPersistDocsRelationNotSet(BasePersistDocsDisabled):
"""
Without providing `persist_docs.relation` config, table comments shouldn't be added by default.
"""

@pytest.fixture(scope="class")
def project_config_update(self):
return {
"models": {
"test": {
"+persist_docs": {
"columns": True,
},
}
}
}