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

fix docstring duplication error issue #2054 #2080

Merged
merged 2 commits into from
Feb 11, 2020
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
2 changes: 2 additions & 0 deletions core/dbt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,8 @@ def raise_duplicate_resource_name(node_1, node_2):
get_func = 'ref("{}")'.format(duped_name)
elif node_1.resource_type == NodeType.Source:
get_func = 'source("{}", "{}")'.format(node_1.source_name, duped_name)
elif node_1.resource_type == NodeType.Documentation:
get_func = 'doc("{}")'.format(duped_name)
elif node_1.resource_type == NodeType.Test and 'schema' in node_1.tags:
return

Expand Down
2 changes: 1 addition & 1 deletion core/dbt/parser/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def add_macro(self, source_file: SourceFile, macro: ParsedMacro):
self.get_file(source_file).macros.append(macro.unique_id)

def add_doc(self, source_file: SourceFile, doc: ParsedDocumentation):
# Docs also can be overwritten (should they be?)
_check_duplicates(doc, self.docs)
self.docs[doc.unique_id] = doc
self.get_file(source_file).docs.append(doc.unique_id)

Expand Down
7 changes: 7 additions & 0 deletions test/integration/035_docs_blocks/duplicate_docs/docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% docs my_model_doc %}
a doc string
{% enddocs %}

{% docs my_model_doc %}
duplicate doc string
{% enddocs %}
1 change: 1 addition & 0 deletions test/integration/035_docs_blocks/duplicate_docs/model.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select 1 as id, 'joe' as first_name
5 changes: 5 additions & 0 deletions test/integration/035_docs_blocks/duplicate_docs/schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: 2

models:
- name: model
description: "{{ doc('my_model_doc') }}"
18 changes: 18 additions & 0 deletions test/integration/035_docs_blocks/test_docs_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,21 @@ def test_postgres_invalid_doc_ref(self):
# The run should fail since we could not find the docs reference.
with self.assertRaises(dbt.exceptions.CompilationException):
self.run_dbt(expect_pass=False)

class TestDuplicateDocsBlock(DBTIntegrationTest):
@property
def schema(self):
return 'docs_blocks_035'

@staticmethod
def dir(path):
return os.path.normpath(path)

@property
def models(self):
return self.dir("duplicate_docs")

@use_profile('postgres')
def test_postgres_duplicate_doc_ref(self):
with self.assertRaises(dbt.exceptions.CompilationException):
self.run_dbt(expect_pass=False)