From fa547021eb59dae34399b8240aa36ad37b990006 Mon Sep 17 00:00:00 2001 From: Connor McArthur Date: Tue, 28 Mar 2017 13:51:35 -0400 Subject: [PATCH 1/3] always release connections at the end of execute_node --- dbt/runner.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/dbt/runner.py b/dbt/runner.py index 68b69c3a1e9..e7134cd73d5 100644 --- a/dbt/runner.py +++ b/dbt/runner.py @@ -478,23 +478,25 @@ def execute_node(self, node, existing): adapter = get_adapter(profile) connection = adapter.begin(profile, node.get('name')) - logger.debug("executing node %s", node.get('unique_id')) + try: + logger.debug("executing node %s", node.get('unique_id')) + + if node.get('skip') is True: + return "SKIP" - if node.get('skip') is True: - return "SKIP" + node = self.inject_runtime_config(node) - node = self.inject_runtime_config(node) + if is_type(node, NodeType.Model): + result = execute_model(profile, node, existing) + elif is_type(node, NodeType.Test): + result = execute_test(profile, node) + elif is_type(node, NodeType.Archive): + result = execute_archive(profile, node, self.node_context(node)) - if is_type(node, NodeType.Model): - result = execute_model(profile, node, existing) - elif is_type(node, NodeType.Test): - result = execute_test(profile, node) - elif is_type(node, NodeType.Archive): - result = execute_archive(profile, node, self.node_context(node)) + adapter.commit(connection) - adapter.commit(connection) - adapter.close(connection) - adapter.release_connection(profile, node.get('name')) + finally: + adapter.release_connection(profile, node.get('name')) return result From 25bb23a27c55fa8ad00e6aa4908c28947c7bb9ab Mon Sep 17 00:00:00 2001 From: Connor McArthur Date: Tue, 28 Mar 2017 16:39:36 -0400 Subject: [PATCH 2/3] pep8 --- dbt/runner.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dbt/runner.py b/dbt/runner.py index e7134cd73d5..7d32438bf82 100644 --- a/dbt/runner.py +++ b/dbt/runner.py @@ -491,7 +491,8 @@ def execute_node(self, node, existing): elif is_type(node, NodeType.Test): result = execute_test(profile, node) elif is_type(node, NodeType.Archive): - result = execute_archive(profile, node, self.node_context(node)) + result = execute_archive( + profile, node, self.node_context(node)) adapter.commit(connection) From ad5f0e26dec5ae389327b1c169f3945f2648e88d Mon Sep 17 00:00:00 2001 From: Connor McArthur Date: Wed, 29 Mar 2017 09:51:09 -0400 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6905ccc37e8..1d29c690d20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Fix run levels ([#343](https://github.com/fishtown-analytics/dbt/pull/343), [#340](https://github.com/fishtown-analytics/dbt/issues/340), [#338](https://github.com/fishtown-analytics/dbt/issues/338)) - Fix concurrency, open a unique transaction per model ([#345](https://github.com/fishtown-analytics/dbt/pull/345), [#336](https://github.com/fishtown-analytics/dbt/issues/336)) - Handle concurrent `DROP ... CASCADE`s in Redshift ([#349](https://github.com/fishtown-analytics/dbt/pull/349)) +- Always release connections (use `try .. finally`) ([#354](https://github.com/fishtown-analytics/dbt/pull/354)) ### Changes