From 1147aa0618647b4bf69586887a72dfa978ee6246 Mon Sep 17 00:00:00 2001 From: Jesse Lax Date: Wed, 6 Oct 2021 20:22:28 -0400 Subject: [PATCH] replace `logger.warning` with `warn_or_error` Uses `warn_or_error` to log _or_ raise errors depending on arguments passed. --- CHANGELOG.md | 2 ++ core/dbt/task/list.py | 6 +++--- core/dbt/task/runnable.py | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07a31529799..44a8c9ca689 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - Enable cataloging of unlogged Postgres tables ([3961](https://github.com/dbt-labs/dbt/issues/3961), [#3993](https://github.com/dbt-labs/dbt/pull/3993)) - Fix multiple disabled nodes ([#4013](https://github.com/dbt-labs/dbt/issues/4013), [#4018](https://github.com/dbt-labs/dbt/pull/4018)) - Fix multiple partial parsing errors ([#3996](https://github.com/dbt-labs/dbt/issues/3006), [#4020](https://github.com/dbt-labs/dbt/pull/4018)) +- Return an error instead of a warning when runing with `--warn-error` and no models are selected ([#4006](https://github.com/dbt-labs/dbt/issues/4006), [#4019](https://github.com/dbt-labs/dbt/pull/4019)) ### Under the hood @@ -38,6 +39,7 @@ Contributors: - [@kadero](https://github.com/kadero) ([#3952](https://github.com/dbt-labs/dbt/pull/3953)) - [@samlader](https://github.com/samlader) ([#3993](https://github.com/dbt-labs/dbt/pull/3993)) - [@yu-iskw](https://github.com/yu-iskw) ([#3967](https://github.com/dbt-labs/dbt/pull/3967)) +- [@laxjesse](https://github.com/laxjesse) ([#4019](https://github.com/dbt-labs/dbt/pull/4019)) ## dbt 0.21.0 (October 04, 2021) diff --git a/core/dbt/task/list.py b/core/dbt/task/list.py index 85277e07b7e..19240321afa 100644 --- a/core/dbt/task/list.py +++ b/core/dbt/task/list.py @@ -8,8 +8,8 @@ from dbt.task.runnable import GraphRunnableTask, ManifestTask from dbt.task.test import TestSelector from dbt.node_types import NodeType -from dbt.exceptions import RuntimeException, InternalException -from dbt.logger import log_manager, GLOBAL_LOGGER as logger +from dbt.exceptions import RuntimeException, InternalException, warn_or_error +from dbt.logger import log_manager class ListTask(GraphRunnableTask): @@ -61,7 +61,7 @@ def _iterate_selected_nodes(self): spec = self.get_selection_spec() nodes = sorted(selector.get_selected(spec)) if not nodes: - logger.warning('No nodes selected!') + warn_or_error('No nodes selected!') return if self.manifest is None: raise InternalException( diff --git a/core/dbt/task/runnable.py b/core/dbt/task/runnable.py index d337379b54d..779b7428cf9 100644 --- a/core/dbt/task/runnable.py +++ b/core/dbt/task/runnable.py @@ -41,6 +41,7 @@ NotImplementedException, RuntimeException, FailFastException, + warn_or_error, ) from dbt.graph import ( @@ -443,8 +444,8 @@ def run(self): ) if len(self._flattened_nodes) == 0: - logger.warning("\nWARNING: Nothing to do. Try checking your model " - "configs and model specification args") + warn_or_error("\nWARNING: Nothing to do. Try checking your model " + "configs and model specification args") result = self.get_result( results=[], generated_at=datetime.utcnow(),