Skip to content

Commit

Permalink
Merge pull request #2584 from fishtown-analytics/fix/plus-prefixed-hooks
Browse files Browse the repository at this point in the history
Fix prefixing support to not render "+pre-hook"
  • Loading branch information
beckjake authored Jun 23, 2020
2 parents 3270255 + d38fd80 commit a45f6be
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## dbt 0.17.1 (Release TBD)


### Fixes
- dbt config-version: 2 now properly defers rendering `+pre-hook` and `+post-hook` fields. ([#2583](https:/fishtown-analytics/dbt/issues/2583), [#2854](https:/fishtown-analytics/dbt/pull/2854))


## dbt 0.17.1rc1 (June 19, 2020)


Expand All @@ -16,7 +21,7 @@

Contributors:
- [@bodschut](https:/bodschut) ([#2550](https:/fishtown-analytics/dbt/pull/2550))

## dbt 0.17.0 (June 08, 2020)

### Fixes
Expand Down
11 changes: 6 additions & 5 deletions core/dbt/config/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def should_render_keypath_v1(self, keypath: Keypath) -> bool:
if first in {'on-run-start', 'on-run-end', 'query-comment'}:
return False
# models have two things to avoid
if first in {'seeds', 'models', 'snapshots', 'seeds'}:
if first in {'seeds', 'models', 'snapshots'}:
# model-level hooks
if 'pre-hook' in keypath or 'post-hook' in keypath:
return False
Expand All @@ -102,11 +102,12 @@ def should_render_keypath_v2(self, keypath: Keypath) -> bool:
return False

if first in {'seeds', 'models', 'snapshots', 'seeds'}:
keypath_parts = {
(k.lstrip('+') if isinstance(k, str) else k)
for k in keypath
}
# model-level hooks
if 'pre-hook' in keypath or 'post-hook' in keypath:
return False
# model-level 'vars' declarations
if 'vars' in keypath:
if 'pre-hook' in keypath_parts or 'post-hook' in keypath_parts:
return False

return True
Expand Down
17 changes: 17 additions & 0 deletions test/integration/014_hook_tests/test_model_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,23 @@ def test_postgres_hooks_on_seeds(self):
self.assertEqual(len(res), 1, 'Expected exactly one item')


class TestPrePostModelHooksOnSeedsPlusPrefixed(TestPrePostModelHooksOnSeeds):
@property
def project_config(self):
return {
'config-version': 2,
'data-paths': ['data'],
'models': {},
'seeds': {
'+post-hook': [
'alter table {{ this }} add column new_col int',
'update {{ this }} set new_col = 1'
],
'quote_columns': False,
},
}


class TestPrePostModelHooksOnSnapshots(DBTIntegrationTest):
@property
def schema(self):
Expand Down
2 changes: 1 addition & 1 deletion test/integration/048_rpc_test/test_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def is_up(self):

def start(self):
super().start()
for _ in range(30):
for _ in range(60):
if self.is_up():
break
time.sleep(0.5)
Expand Down

0 comments on commit a45f6be

Please sign in to comment.