Skip to content

Commit

Permalink
Add --warn-error-options (#6520)
Browse files Browse the repository at this point in the history
* adding --warn-error-options

Co-authored-by: Github Build Bot <buildbot@fishtownanalytics.com>
  • Loading branch information
MichelleArk and FishtownBuildBot authored Jan 11, 2023
1 parent dd4b47d commit 7a61602
Show file tree
Hide file tree
Showing 31 changed files with 350 additions and 13,115 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Features-20230104-181003.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Features
body: '--warn-error-options: Treat warnings as errors for specific events, based on
user configuration'
time: 2023-01-04T18:10:03.203142-05:00
custom:
Author: MichelleArk
Issue: "6165"
1 change: 1 addition & 0 deletions core/dbt/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def cli_runner():
@p.version
@p.version_check
@p.warn_error
@p.warn_error_options
@p.write_json
def cli(ctx, **kwargs):
"""An ELT tool for managing your SQL transformations and data models.
Expand Down
15 changes: 15 additions & 0 deletions core/dbt/cli/option_types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from click import ParamType
import yaml

from dbt.helper_types import WarnErrorOptions


class YAML(ParamType):
"""The Click YAML type. Converts YAML strings into objects."""
Expand All @@ -17,6 +19,19 @@ def convert(self, value, param, ctx):
self.fail(f"String '{value}' is not valid YAML", param, ctx)


class WarnErrorOptionsType(YAML):
"""The Click WarnErrorOptions type. Converts YAML strings into objects."""

name = "WarnErrorOptionsType"

def convert(self, value, param, ctx):
include_exclude = super().convert(value, param, ctx)

return WarnErrorOptions(
include=include_exclude.get("include", []), exclude=include_exclude.get("exclude", [])
)


class Truthy(ParamType):
"""The Click Truthy type. Converts strings into a "truthy" type"""

Expand Down
17 changes: 14 additions & 3 deletions core/dbt/cli/params.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path, PurePath

import click
from dbt.cli.option_types import YAML
from dbt.cli.option_types import YAML, WarnErrorOptionsType
from dbt.cli.resolvers import default_project_dir, default_profiles_dir


Expand Down Expand Up @@ -358,9 +358,20 @@
)

warn_error = click.option(
"--warn-error/--no-warn-error",
"--warn-error",
envvar="DBT_WARN_ERROR",
help="If dbt would normally warn, instead raise an exception. Examples include --models that selects nothing, deprecations, configurations with no associated models, invalid test configurations, and missing sources/refs in tests.",
help="If dbt would normally warn, instead raise an exception. Examples include --select that selects nothing, deprecations, configurations with no associated models, invalid test configurations, and missing sources/refs in tests.",
default=None,
flag_value=True,
)

warn_error_options = click.option(
"--warn-error-options",
envvar="DBT_WARN_ERROR_OPTIONS",
default=None,
help="""If dbt would normally warn, instead raise an exception based on include/exclude configuration. Examples include --select that selects nothing, deprecations, configurations with no associated models, invalid test configurations,
and missing sources/refs in tests. This argument should be a YAML string, with keys 'include' or 'exclude'. eg. '{"include": "all", "exclude": ["NoNodesForSelectionCriteria"]}'""",
type=WarnErrorOptionsType(),
)

write_json = click.option(
Expand Down
12 changes: 8 additions & 4 deletions core/dbt/config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@
from dbt.config import Profile, Project, read_user_config
from dbt.config.renderer import DbtProjectYamlRenderer, ProfileRenderer
from dbt.events.functions import fire_event
from dbt.events.types import InvalidVarsYAML
from dbt.exceptions import DbtValidationError, VarsArgNotYamlDictError
from dbt.events.types import InvalidOptionYAML
from dbt.exceptions import DbtValidationError, OptionNotYamlDict


def parse_cli_vars(var_string: str) -> Dict[str, Any]:
return parse_cli_yaml_string(var_string, "vars")


def parse_cli_yaml_string(var_string: str, cli_option_name: str) -> Dict[str, Any]:
try:
cli_vars = yaml_helper.load_yaml_text(var_string)
var_type = type(cli_vars)
if var_type is dict:
return cli_vars
else:
raise VarsArgNotYamlDictError(var_type)
raise OptionNotYamlDict(var_type, cli_option_name)
except DbtValidationError:
fire_event(InvalidVarsYAML())
fire_event(InvalidOptionYAML(option_name=cli_option_name))
raise


Expand Down
1 change: 1 addition & 0 deletions core/dbt/contracts/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ class UserConfig(ExtensibleDbtClassMixin, Replaceable, UserConfigContract):
printer_width: Optional[int] = None
write_json: Optional[bool] = None
warn_error: Optional[bool] = None
warn_error_options: Optional[Dict[str, Union[str, List[str]]]] = None
log_format: Optional[str] = None
debug: Optional[bool] = None
version_check: Optional[bool] = None
Expand Down
Binary file modified core/dbt/docs/build/doctrees/environment.pickle
Binary file not shown.
2 changes: 1 addition & 1 deletion core/dbt/docs/build/html/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 1ee31fc16e025fb98598189ba2cb5fcb
config: e27d6c1c419f2f0af393858cdf674109
tags: 645f666f9bcd5a90fca523b33c5a78b7

This file was deleted.

3 changes: 3 additions & 0 deletions core/dbt/docs/build/html/_static/basic.css
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,15 @@ aside.sidebar {
p.sidebar-title {
font-weight: bold;
}

nav.contents,
aside.topic,
div.admonition, div.topic, blockquote {
clear: left;
}

/* -- topics ---------------------------------------------------------------- */

nav.contents,
aside.topic,
div.topic {
Expand Down Expand Up @@ -606,6 +608,7 @@ ol.simple p,
ul.simple p {
margin-bottom: 0;
}

aside.footnote > span,
div.citation > span {
float: left;
Expand Down
Loading

0 comments on commit 7a61602

Please sign in to comment.