Skip to content

Commit

Permalink
Fix for pre-hooks outside of transactions (#623)
Browse files Browse the repository at this point in the history
* Fix for pre-hooks outside of transactions #576

* improve tests
  • Loading branch information
drewbanin authored Dec 18, 2017
1 parent 8ff58a2 commit eba47d0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{% macro run_hooks(hooks, inside_transaction=True) %}
{% for hook in hooks | selectattr('transaction', 'equalto', inside_transaction) %}
{% if not inside_transaction and loop.first %}
{% call statement(auto_begin=inside_transaction) %}
commit;
{% endcall %}
{% endif %}
{% call statement(auto_begin=inside_transaction) %}
{{ hook.get('sql') }}
{% endcall %}
Expand Down
17 changes: 15 additions & 2 deletions test/integration/014_hook_tests/test_model_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,21 @@ def project_config(self):
'macro-paths': ['test/integration/014_hook_tests/macros'],
'models': {
'test': {
'pre-hook': MODEL_PRE_HOOK,
'post-hook': MODEL_POST_HOOK,
'pre-hook': [
# inside transaction (runs second)
MODEL_PRE_HOOK,

# outside transaction (runs first)
{"sql": "vacuum {{ this.schema }}.on_model_hook", "transaction": False},
],

'post-hook':[
# outside transaction (runs second)
{"sql": "vacuum {{ this.schema }}.on_model_hook", "transaction": False},

# inside transaction (runs first)
MODEL_POST_HOOK,
]
}
}
}
Expand Down

0 comments on commit eba47d0

Please sign in to comment.