diff --git a/.changes/unreleased/Fixes-20240323-122018.yaml b/.changes/unreleased/Fixes-20240323-122018.yaml new file mode 100644 index 00000000000..a165511283c --- /dev/null +++ b/.changes/unreleased/Fixes-20240323-122018.yaml @@ -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 diff --git a/core/dbt/cli/main.py b/core/dbt/cli/main.py index 6677233bda7..deff7d8d341 100644 --- a/core/dbt/cli/main.py +++ b/core/dbt/cli/main.py @@ -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, diff --git a/tests/functional/dbt_runner/test_dbt_runner.py b/tests/functional/dbt_runner/test_dbt_runner.py index b0375b1f730..c332490e2d7 100644 --- a/tests/functional/dbt_runner/test_dbt_runner.py +++ b/tests/functional/dbt_runner/test_dbt_runner.py @@ -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") diff --git a/tests/unit/test_cli_flags.py b/tests/unit/test_cli_flags.py index 7c605c2eab0..6bf9d692e0e 100644 --- a/tests/unit/test_cli_flags.py +++ b/tests/unit/test_cli_flags.py @@ -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") @@ -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"