Skip to content

Commit

Permalink
Merge pull request #2958 from fishtown-analytics/fix/keyerror-defer-m…
Browse files Browse the repository at this point in the history
…issing-parent

Fix KeyError from defer + deletion
  • Loading branch information
jtcohen6 authored Dec 17, 2020
2 parents aff7299 + f382da6 commit 97ab130
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- Allow docs blocks in exposure descriptions ([#2913](https:/fishtown-analytics/dbt/issues/2913), [#2920](https:/fishtown-analytics/dbt/pull/2920))
- Use original file path instead of absolute path as checksum for big seeds ([#2927](https:/fishtown-analytics/dbt/issues/2927), [#2939](https:/fishtown-analytics/dbt/pull/2939))
- Defer if and only if upstream reference does not exist in current environment namespace ([#2909](https:/fishtown-analytics/dbt/issues/2909), [#2946](https:/fishtown-analytics/dbt/pull/2946))
- Fix KeyError if deferring to a manifest with a since-deleted source, ephemeral model, or test ([#2875](https:/fishtown-analytics/dbt/issues/2875), [#2958](https:/fishtown-analytics/dbt/pull/2958))

### Under the hood
- Bump hologram version to 0.0.11. Add scripts/dtr.py ([#2888](https:/fishtown-analytics/dbt/issues/2840),[#2889](https:/fishtown-analytics/dbt/pull/2889))
Expand Down
3 changes: 2 additions & 1 deletion core/dbt/contracts/graph/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ def build_edges(nodes: List[ManifestNode]):
for node in nodes:
backward_edges[node.unique_id] = node.depends_on_nodes[:]
for unique_id in node.depends_on_nodes:
forward_edges[unique_id].append(node.unique_id)
if unique_id in forward_edges.keys():
forward_edges[unique_id].append(node.unique_id)
return _sort_values(forward_edges), _sort_values(backward_edges)


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2
models:
- name: view_model
columns:
- name: id
tests:
- unique
- not_null
- name: name
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{ config(materialized='table') }}
select 1 as fun
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from {{ ref('seed') }}
21 changes: 21 additions & 0 deletions test/integration/062_defer_state_test/test_defer_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ def run_defer_iff_not_exists(self):
# because the seed now exists in our schema, we shouldn't defer it
assert self.other_schema not in results[0].node.compiled_sql
assert self.unique_schema() in results[0].node.compiled_sql

def run_defer_deleted_upstream(self):
results = self.run_dbt(['seed'])
assert len(results) == 1
results = self.run_dbt(['run'])
assert len(results) == 2

# copy files over from the happy times when we had a good target
self.copy_state()

self.use_default_project({'source-paths': ['changed_models_missing']})
# ephemeral_model is now gone. previously this caused a
# keyerror (dbt#2875), now it should pass
self.run_dbt(
['run', '-m', 'view_model', '--state', 'state', '--defer', '--target', 'otherschema'],
expect_pass=True,
)

@use_profile('postgres')
def test_postgres_state_changetarget(self):
Expand All @@ -142,6 +159,10 @@ def test_postgres_state_changedir(self):
@use_profile('postgres')
def test_postgres_state_defer_iffnotexists(self):
self.run_defer_iff_not_exists()

@use_profile('postgres')
def test_postgres_state_defer_deleted_upstream(self):
self.run_defer_deleted_upstream()

@use_profile('snowflake')
def test_snowflake_state_changetarget(self):
Expand Down

0 comments on commit 97ab130

Please sign in to comment.