Skip to content

Feat(dbt_cli): Add support for '--profile' and '--target'#5174

Merged
erindru merged 2 commits intomainfrom
erin/dbt-profile-target-flags
Aug 18, 2025
Merged

Feat(dbt_cli): Add support for '--profile' and '--target'#5174
erindru merged 2 commits intomainfrom
erin/dbt-profile-target-flags

Conversation

@erindru
Copy link
Collaborator

@erindru erindru commented Aug 18, 2025

Enables the usage of the --profile flag (to select a specific DBT profile) and the --target flag (to select a target within that profile) for the sqlmesh_dbt CLI.

Also adds a global error handler so when the target or profile doesnt match, we dont print a stack trace.

from sqlmesh.dbt.loader import sqlmesh_config

dbt_python_config = sqlmesh_config(project_root=dbt_project_file.parent)
dbt_python_config = sqlmesh_config(
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 config_loader_kwargs parameter was added to Context so it could flow through to here.

I first attempted to make these arguments to the DbtLoader, but theyre needed to work out the ConnectionConfig and by the time DbtLoader is invoked it's too late

raise ConfigError(
f"Target '{target_name}' not specified in profiles for '{context.profile_name}'."
f"Target '{target_name}' not specified in profiles for '{context.profile_name}'. "
f"The valid target names for this profile are:\n{target_names}"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I noticed that the dbt cli lists valid targets if you get the profile correct but the target wrong, so I updated this to do the same

@erindru erindru merged commit e574577 into main Aug 18, 2025
27 of 28 checks passed
@erindru erindru deleted the erin/dbt-profile-target-flags branch August 18, 2025 21:31
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