Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more work on flags
  • Loading branch information
ChenyuLInx committed Feb 7, 2023
commit 8ed644ff1e2c47eb74cb5c543ba16444c7820ae7
7 changes: 7 additions & 0 deletions core/dbt/cli/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from dbt.config.profile import read_user_config
from dbt.contracts.project import UserConfig
from dbt.cli.option_types import WarnErrorOptionsType

if os.name != "nt":
# https://bugs.python.org/issue41567
Expand Down Expand Up @@ -80,6 +81,12 @@ def assign_params(ctx, params_assigned_from_default):
for param_assigned_from_default in params_assigned_from_default:
user_config_param_value = getattr(user_config, param_assigned_from_default, None)
if user_config_param_value is not None:
# TODO Conversion should happen here to make sure types are consistent with the flag
# extract into a function
if param_assigned_from_default in ["warn_error_options"]:
user_config_param_value = WarnErrorOptionsType().convert(
user_config_param_value, None, None
)
object.__setattr__(
self, param_assigned_from_default.upper(), user_config_param_value
)
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/cli/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def _version_callback(ctx, _param, value):
warn_error_options = click.option(
"--warn-error-options",
envvar="DBT_WARN_ERROR_OPTIONS",
default=None,
default="{}",
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(),
Expand Down
4 changes: 4 additions & 0 deletions core/dbt/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def set_from_args(args: Namespace, user_config):
ctx = cli.make_context("run", ["run"])
flags = Flags(ctx, user_config)
for arg_name, args_param_value in vars(args).items():
if arg_name in ["warn_error_options"]:
from dbt.cli.option_types import WarnErrorOptionsType

args_param_value = WarnErrorOptionsType().convert(args_param_value, None, None)
object.__setattr__(flags, arg_name.upper(), args_param_value)
object.__setattr__(flags, arg_name.lower(), args_param_value)
GLOBAL_FLAGS = flags # type: ignore
Expand Down
9 changes: 9 additions & 0 deletions core/dbt/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ def run_dbt(args: List[str] = None, expect_pass=True):
args = ["run"]

print("\n\nInvoking dbt with {}".format(args))
from dbt.flags import get_flags

flags = get_flags()
project_dir = getattr(flags, "PROJECT_DIR", None)
profiles_dir = getattr(flags, "PROFILES_DIR", None)
if project_dir and "--project-dir" not in args:
args.extend(["--project-dir", project_dir])
if profiles_dir and "--profiles-dir" not in args:
args.extend(["--profiles-dir", profiles_dir])
dbt = dbtRunner()
res, success = dbt.invoke(args)

Expand Down
4 changes: 2 additions & 2 deletions tests/functional/profiles/test_profile_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from contextlib import contextmanager
from pathlib import Path
from argparse import Namespace

import dbt.flags as flags

Expand Down Expand Up @@ -91,7 +92,7 @@ def environ(env):
class TestProfiles:
def dbt_debug(self, project_dir_cli_arg=None, profiles_dir_cli_arg=None):
# begin with no command-line args or user config (from profiles.yml)
flags.set_from_args({}, {})
flags.set_from_args(Namespace(), {})
command = ["debug"]

if project_dir_cli_arg:
Expand Down Expand Up @@ -144,7 +145,6 @@ def test_profiles(
# start in the specified directory
if working_directory is not None:
os.chdir(working_directory)

# default case with profiles.yml in the HOME directory
_, stdout = self.dbt_debug(project_dir_cli_arg)
assert f"Using profiles.yml file at {profiles_home_root}" in stdout
Expand Down