Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expect that the args variable is un-modified by dbt.invoke(args) #9809

Merged
merged 7 commits into from
Apr 2, 2024
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20240323-122018.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Make `args` variable to be un-modified by `dbt.invoke(args)`
time: 2024-03-23T12:20:18.170948-06:00
custom:
Author: dbeatty10
Issue: 8938 9787
2 changes: 1 addition & 1 deletion core/dbt/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(

def invoke(self, args: List[str], **kwargs) -> dbtRunnerResult:
try:
dbt_ctx = cli.make_context(cli.name, args)
dbt_ctx = cli.make_context(cli.name, args.copy())
dbt_ctx.obj = {
"manifest": self.manifest,
"callbacks": self.callbacks,
Expand Down
6 changes: 6 additions & 0 deletions tests/functional/dbt_runner/test_dbt_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ def test_pass_in_manifest(self, project, dbt):
assert result.success
assert len(FACTORY.adapters) == 1

def test_pass_in_args_variable(self, dbt):
args = ["--log-format", "text"]
args_before = args.copy()
dbt.invoke(args)
assert args == args_before


class TestDbtRunnerQueryComments:
@pytest.fixture(scope="class")
Expand Down
9 changes: 8 additions & 1 deletion tests/unit/test_cli_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TestFlags:
def make_dbt_context(
self, context_name: str, args: List[str], parent: Optional[click.Context] = None
) -> click.Context:
ctx = cli.make_context(context_name, args, parent)
ctx = cli.make_context(context_name, args.copy(), parent)
return ctx

@pytest.fixture(scope="class")
Expand All @@ -29,6 +29,13 @@ def run_context(self) -> click.Context:
def project_flags(self) -> ProjectFlags:
return ProjectFlags()

def test_cli_args_unmodified(self):
args = ["--target", "my_target"]
args_before = args.copy()
self.make_dbt_context("context", args)

assert args == args_before

def test_which(self, run_context):
flags = Flags(run_context)
assert flags.WHICH == "run"
Expand Down