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 diff --git a/dbt/runner.py b/dbt/runner.py index 68b69c3a1e9..7d32438bf82 100644 --- a/dbt/runner.py +++ b/dbt/runner.py @@ -478,23 +478,26 @@ 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