Skip to content

Feat(dbt_cli): Add support for --vars#5205

Merged
erindru merged 4 commits intomainfrom
erin/dbt-vars
Aug 25, 2025
Merged

Feat(dbt_cli): Add support for --vars#5205
erindru merged 4 commits intomainfrom
erin/dbt-vars

Conversation

@erindru
Copy link
Collaborator

@erindru erindru commented Aug 21, 2025

Add support for the --vars '<yaml blob>' syntax of the dbt core cli.

It passes these in config_loader_kwargs so the variables are available before the project is loaded

select 1
""")

result = invoke_cli(["list", "--vars", "foo: bar"])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to test more variances like:

$ dbt run --vars '{"key": "value", "date": 20180101}'
$ dbt run --vars '{key: value, date: 20180101}'

or are we confident that the YAML parser takes care of it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The YAML parser does indeed take care of it, but I added a test test_yaml_param_type() to prove it

raise ValueError(f"Unexpected click context object: {type(ctx.obj)}")
return ctx.obj

dbt_operations = ctx.obj(vars=vars)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we handle this differently from profile / target`?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--profile / --target are top level dbt options - they show in dbt --help and apply to every subcommand.

--vars only applies to certain subcommands. eg it shows in dbt list --help and dbt run --help but not dbt source --help

@erindru erindru force-pushed the erin/dbt-vars branch 2 times, most recently from 0324699 to c5cda03 Compare August 25, 2025 06:06
@erindru erindru merged commit 8751ee5 into main Aug 25, 2025
28 checks passed
@erindru erindru deleted the erin/dbt-vars branch August 25, 2025 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants