Skip to content

Commit

Permalink
Merge pull request gocardless#34 from tucows/master
Browse files Browse the repository at this point in the history
Add --warn-error option to dbt
  • Loading branch information
irfanhabib authored Aug 12, 2021
2 parents 9778665 + b56cadd commit 239622f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ It will also need access to the `dbt` CLI, which should either be on your `PATH`

## Usage

There are four operators currently implemented:
There are five operators currently implemented:

* `DbtDocsGenerateOperator`
* Calls [`dbt docs generate`](https://docs.getdbt.com/reference/commands/cmd-docs)
* `DbtSeedOperator`
* Calls [`dbt seed`](https://docs.getdbt.com/docs/seed)
* `DbtSnapshotOperator`
Expand Down Expand Up @@ -85,6 +87,8 @@ Each of the above operators accept the following arguments:
* The `dbt` CLI. Defaults to `dbt`, so assumes it's on your `PATH`
* `verbose`
* The operator will log verbosely to the Airflow logs
* `warn_error`
* If set to `True`, passes `--warn-error` argument to `dbt` command and will treat warnings as errors

Typically you will want to use the `DbtRunOperator`, followed by the `DbtTestOperator`, as shown earlier.

Expand Down
9 changes: 8 additions & 1 deletion airflow_dbt/hooks/dbt_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class DbtCliHook(BaseHook):
:type full_refresh: bool
:param models: If set, passed as the `--models` argument to the `dbt` command
:type models: str
:param warn_error: If `True`, treat warnings as errors.
:type warn_error: bool
:param exclude: If set, passed as the `--exclude` argument to the `dbt` command
:type exclude: str
:param select: If set, passed as the `--select` argument to the `dbt` command
Expand All @@ -48,7 +50,8 @@ def __init__(self,
select=None,
dbt_bin='dbt',
output_encoding='utf-8',
verbose=True):
verbose=True,
warn_error=False):
self.profiles_dir = profiles_dir
self.dir = dir
self.target = target
Expand All @@ -61,6 +64,7 @@ def __init__(self,
self.select = select
self.dbt_bin = dbt_bin
self.verbose = verbose
self.warn_error = warn_error
self.output_encoding = output_encoding

def _dump_vars(self):
Expand Down Expand Up @@ -106,6 +110,9 @@ def run_cli(self, *command):
if self.full_refresh:
dbt_cmd.extend(['--full-refresh'])

if self.warn_error:
dbt_cmd.insert(1, '--warn-error')

if self.verbose:
self.log.info(" ".join(dbt_cmd))

Expand Down
7 changes: 6 additions & 1 deletion airflow_dbt/operators/dbt_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class DbtBaseOperator(BaseOperator):
:type full_refresh: bool
:param models: If set, passed as the `--models` argument to the `dbt` command
:type models: str
:param warn_error: If `True`, treat warnings as errors.
:type warn_error: bool
:param exclude: If set, passed as the `--exclude` argument to the `dbt` command
:type exclude: str
:param select: If set, passed as the `--select` argument to the `dbt` command
Expand All @@ -45,6 +47,7 @@ def __init__(self,
select=None,
dbt_bin='dbt',
verbose=True,
warn_error=False,
full_refresh=False,
data=False,
schema=False,
Expand All @@ -64,6 +67,7 @@ def __init__(self,
self.select = select
self.dbt_bin = dbt_bin
self.verbose = verbose
self.warn_error = warn_error
self.create_hook()

def create_hook(self):
Expand All @@ -79,7 +83,8 @@ def create_hook(self):
exclude=self.exclude,
select=self.select,
dbt_bin=self.dbt_bin,
verbose=self.verbose)
verbose=self.verbose,
warn_error=self.warn_error)

return self.hook

Expand Down

0 comments on commit 239622f

Please sign in to comment.