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

(fixes #1119) Ignore dependencies into dbt schemas from external schemas #1120

Merged
merged 2 commits into from
Nov 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion dbt/adapters/postgres/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ def _link_cached_relations(self, manifest, schemas):
identifier=refed_name)
dependent = self.Relation.create(schema=dep_schema,
identifier=dep_name)
self.cache.add_link(dependent, referenced)

# don't record in cache if this relation isn't in a relevant schema
if refed_schema in schemas:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@beckjake do you think we need to do a case-insensitive check here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it needs to be refed_schema.lower() in schemas.

self.cache.add_link(dependent, referenced)

def _list_relations(self, schema, model_name=None):
sql = """
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

select 1 as id
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,39 @@ def test__postgres__external_reference(self):
self.assertEquals(len(self.run_dbt()), 1)
# running it again should succeed
self.assertEquals(len(self.run_dbt()), 1)

# The opposite of the test above -- check that external relations that
# depend on a dbt model do not create issues with caching
class TestExternalDependency(DBTIntegrationTest):
@property
def schema(self):
return "external_dependency_037"

@property
def models(self):
return "test/integration/037_external_reference_test/standalone_models"

def tearDown(self):
# This has to happen before we drop the external schema, because
# otherwise postgres hangs forever.
self._drop_schema()
self.adapter.drop_schema(self.external_schema, '__test')
super(TestExternalDependency, self).tearDown()

@use_profile('postgres')
def test__postgres__external_reference(self):
self.assertEquals(len(self.run_dbt()), 1)

# create a view outside of the dbt schema that depends on this model
self.external_schema = self.unique_schema()+'zz'
self.run_sql(
'create schema "{}"'.format(self.external_schema)
)
self.run_sql(
'create view "{}"."external" as (select * from {}.my_model)'
.format(self.external_schema, self.unique_schema())
)

# running it again should succeed
self.assertEquals(len(self.run_dbt()), 1)