Skip to content

Commit

Permalink
Merge pull request #2080 from bubbomb/update-docs-duplicates
Browse files Browse the repository at this point in the history
fix docstring duplication error issue #2054
  • Loading branch information
beckjake authored Feb 11, 2020
2 parents 89c65af + 4ae129d commit 4e58589
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions core/dbt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,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 @@ -121,7 +121,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)

0 comments on commit 4e58589

Please sign in to comment.