-
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
run hooks outside of a transaction #510
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b9930c7
make it possible to issue hooks outside of a transaction
drewbanin 0e60445
wip
drewbanin 7f61366
fix incremental materializations
drewbanin 127563b
Merge branch 'development' into hooks-outside-of-transactions
drewbanin f250d1f
hook contract for on-run-start/on-run-end
drewbanin 6dd7c3e
Merge branch 'hooks-outside-of-transactions' of github.com:fishtown-a…
drewbanin f681f77
make on-run-* hooks work more sanely
drewbanin 2c20689
pep8
drewbanin 022b3d7
make codeclimate happy(-ier)
drewbanin 98e4227
typo
drewbanin df98bcf
fix for bq commit signature
drewbanin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
import json | ||
from dbt.compat import to_string | ||
|
||
|
||
class ModelHookType: | ||
PreHook = 'pre-hook' | ||
PostHook = 'post-hook' | ||
Both = [PreHook, PostHook] | ||
|
||
|
||
def _parse_hook_to_dict(hook_string): | ||
try: | ||
hook_dict = json.loads(hook_string) | ||
except ValueError as e: | ||
hook_dict = {"sql": hook_string} | ||
|
||
if 'transaction' not in hook_dict: | ||
hook_dict['transaction'] = True | ||
|
||
return hook_dict | ||
|
||
|
||
def get_hook_dict(hook): | ||
if isinstance(hook, dict): | ||
hook_dict = hook | ||
else: | ||
hook_dict = _parse_hook_to_dict(to_string(hook)) | ||
|
||
return hook_dict | ||
|
||
|
||
def get_hooks(model, hook_key): | ||
hooks = model.get('config', {}).get(hook_key, []) | ||
|
||
if not isinstance(hooks, (list, tuple)): | ||
hooks = [hooks] | ||
|
||
wrapped = [get_hook_dict(hook) for hook in hooks] | ||
return wrapped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
does this automatically roll back open transactions? would want to be sure we don't create a deadlock because of an open tx
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.
yeah,
release_connection
callsrollback
under the hood if the transaction is open. This change is to fix an issue where we'd try to rollback transactions that weren't open