Skip to content

Commit

Permalink
(fixes #1119) Ignore dependencies into dbt schemas from external schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbanin committed Nov 13, 2018
1 parent 2e32f5f commit 8e36480
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
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:
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)

0 comments on commit 8e36480

Please sign in to comment.