-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Raise CompilationException on duplicate model #568
Changes from all commits
4a479a8
73cf85f
fcba572
c81a01f
a7f7cfe
7bc2cef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import hashlib | ||
import collections | ||
|
||
import dbt.exceptions | ||
import dbt.flags | ||
import dbt.model | ||
import dbt.utils | ||
|
@@ -272,14 +273,27 @@ def parse_sql_nodes(nodes, root_project, projects, tags=None, macros=None): | |
package_name, | ||
node.get('name')) | ||
|
||
# TODO if this is set, raise a compiler error | ||
to_return[node_path] = parse_node(node, | ||
node_path, | ||
root_project, | ||
projects.get(package_name), | ||
projects, | ||
tags=tags, | ||
macros=macros) | ||
node_parsed = parse_node(node, | ||
node_path, | ||
root_project, | ||
projects.get(package_name), | ||
projects, | ||
tags=tags, | ||
macros=macros) | ||
|
||
# Ignore disabled nodes | ||
if not node_parsed['config']['enabled']: | ||
continue | ||
|
||
# Check for duplicate model names | ||
existing_node = to_return.get(node_path) | ||
if existing_node is not None: | ||
raise dbt.exceptions.CompilationException( | ||
'Found models with the same name:\n- %s\n- %s' % ( | ||
existing_node.get('original_file_path'), | ||
node.get('original_file_path'))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need this check in addition to the one in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we still need this check because |
||
|
||
to_return[node_path] = node_parsed | ||
|
||
dbt.contracts.graph.parsed.validate_nodes(to_return) | ||
|
||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{{ | ||
config( | ||
enabled=True, | ||
materialized="table", | ||
) | ||
}} | ||
|
||
select 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{{ | ||
config( | ||
enabled=True, | ||
materialized="table", | ||
) | ||
}} | ||
|
||
select 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{{ | ||
config( | ||
enabled=False, | ||
materialized="table", | ||
) | ||
}} | ||
|
||
select 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{{ | ||
config( | ||
enabled=True, | ||
materialized="table", | ||
) | ||
}} | ||
|
||
select 1 as value |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{{ | ||
config( | ||
materialized = 'table', | ||
) | ||
}} | ||
|
||
select 1 as item |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{{ | ||
config( | ||
materialized = 'table', | ||
enabled = False, | ||
) | ||
}} | ||
|
||
select 1 as item |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
from nose.plugins.attrib import attr | ||
|
||
from dbt.exceptions import CompilationException | ||
from test.integration.base import DBTIntegrationTest | ||
|
||
|
||
class TestDuplicateModelEnabled(DBTIntegrationTest): | ||
|
||
def setUp(self): | ||
DBTIntegrationTest.setUp(self) | ||
|
||
@property | ||
def schema(self): | ||
return "duplicate_model_025" | ||
|
||
@property | ||
def models(self): | ||
return "test/integration/025_duplicate_model_test/models-1" | ||
|
||
@property | ||
def profile_config(self): | ||
return { | ||
"test": { | ||
"outputs": { | ||
"dev": { | ||
"type": "postgres", | ||
"threads": 1, | ||
"host": "database", | ||
"port": 5432, | ||
"user": "root", | ||
"pass": "password", | ||
"dbname": "dbt", | ||
"schema": self.unique_schema() | ||
}, | ||
}, | ||
"target": "dev" | ||
} | ||
} | ||
|
||
@attr(type="postgres") | ||
def test_duplicate_model_enabled(self): | ||
message = "Found models with the same name:.*" | ||
with self.assertRaisesRegexp(CompilationException, message): | ||
self.run_dbt(["run"]) | ||
|
||
|
||
class TestDuplicateModelDisabled(DBTIntegrationTest): | ||
|
||
def setUp(self): | ||
DBTIntegrationTest.setUp(self) | ||
|
||
@property | ||
def schema(self): | ||
return "duplicate_model_025" | ||
|
||
@property | ||
def models(self): | ||
return "test/integration/025_duplicate_model_test/models-2" | ||
|
||
@property | ||
def profile_config(self): | ||
return { | ||
"test": { | ||
"outputs": { | ||
"dev": { | ||
"type": "postgres", | ||
"threads": 1, | ||
"host": "database", | ||
"port": 5432, | ||
"user": "root", | ||
"pass": "password", | ||
"dbname": "dbt", | ||
"schema": self.unique_schema() | ||
}, | ||
}, | ||
"target": "dev" | ||
} | ||
} | ||
|
||
@attr(type="postgres") | ||
def test_duplicate_model_disabled(self): | ||
try: | ||
self.run_dbt(["run"]) | ||
except CompilationException: | ||
self.fail( | ||
"Compilation Exception raised on disabled model") | ||
query = "select value from {schema}.model" \ | ||
.format(schema=self.unique_schema()) | ||
result = self.run_sql(query, fetch="one")[0] | ||
assert result == 1 | ||
|
||
|
||
class TestDuplicateModelEnabledAcrossPackages(DBTIntegrationTest): | ||
|
||
def setUp(self): | ||
DBTIntegrationTest.setUp(self) | ||
|
||
@property | ||
def schema(self): | ||
return "duplicate_model_025" | ||
|
||
@property | ||
def models(self): | ||
return "test/integration/025_duplicate_model_test/models-3" | ||
|
||
@property | ||
def project_config(self): | ||
return { | ||
"repositories": [ | ||
'https://github.com/fishtown-analytics/dbt-integration-project@master' | ||
] | ||
} | ||
|
||
@attr(type="postgres") | ||
def test_duplicate_model_enabled_across_packages(self): | ||
self.run_dbt(["deps"]) | ||
message = "Found models with the same name:.*" | ||
with self.assertRaisesRegexp(CompilationException, message): | ||
self.run_dbt(["run"]) | ||
|
||
|
||
class TestDuplicateModelDisabledAcrossPackages(DBTIntegrationTest): | ||
|
||
def setUp(self): | ||
DBTIntegrationTest.setUp(self) | ||
self.run_sql_file("test/integration/025_duplicate_model_test/seed.sql") | ||
|
||
@property | ||
def schema(self): | ||
return "duplicate_model_025" | ||
|
||
@property | ||
def models(self): | ||
return "test/integration/025_duplicate_model_test/models-4" | ||
|
||
@property | ||
def project_config(self): | ||
return { | ||
"repositories": [ | ||
'https://github.com/fishtown-analytics/dbt-integration-project@master' | ||
] | ||
} | ||
|
||
@attr(type="postgres") | ||
def test_duplicate_model_disabled_across_packages(self): | ||
self.run_dbt(["deps"]) | ||
try: | ||
self.run_dbt(["run"]) | ||
except CompilationException: | ||
self.fail( | ||
"Compilation Exception raised on disabled model") | ||
query = "select 1 from {schema}.table" \ | ||
.format(schema=self.unique_schema()) | ||
result = self.run_sql(query, fetch="one")[0] | ||
assert result == 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks good. @drewbanin we should expand on this error message later on. specifically it'd be nice to tell the user what to do (disable one of these in your dbt_project.yml, or rename one of the models)