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

Add --target and --profile to global config #9081

Merged
merged 15 commits into from
Mar 21, 2024

Conversation

barton996
Copy link
Contributor

@barton996 barton996 commented Nov 15, 2023

resolves #7798
Related to pull/7920

Problem

--profile and --target are not part of the global config and cannot be set once at env var level without using env_var() in profiles.yml. This feature should be provided out of the box as is the case for --profiles-dir.

Solution

--profile and --target have been elevated to global config and can now be set by the DBT_PROFILE and DBT_TARGET env vars.

Checklist

  • I have read the contributing guide and understand what's expected of me
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc) or this PR has already received feedback and approval from Product or DX
  • This PR includes type annotations for new and modified functions

@barton996 barton996 requested a review from a team as a code owner November 15, 2023 08:16
@barton996 barton996 requested a review from emmyoop November 15, 2023 08:16
@cla-bot cla-bot bot added the cla:yes label Nov 15, 2023
Copy link
Contributor

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide.

@barton996
Copy link
Contributor Author

@dbeatty10

Copy link

codecov bot commented Nov 18, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.02%. Comparing base (2c1926c) to head (873af90).
Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9081      +/-   ##
==========================================
- Coverage   88.11%   88.02%   -0.09%     
==========================================
  Files         178      178              
  Lines       22487    22461      -26     
==========================================
- Hits        19815    19772      -43     
- Misses       2672     2689      +17     
Flag Coverage Δ
integration 85.41% <100.00%> (-0.16%) ⬇️
unit 61.73% <100.00%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dbeatty10
Copy link
Contributor

Question

source

@jtcohen6 in the vein of #7036, does the following need to be added to UserConfig?

    profile: Optional[str] = None
    target: Optional[str] = None

Answer

Outside of GitHub, @jtcohen6 and I discussed this, and he replied with the following:

I think it would be confusing to set those in UserConfig, given that:

  • profile is already set in dbt_project.yml
  • default target is already set within each profile

Decision

In light of those considerations, we're going to add profile and target the list of exceptions of global flags not included within UserConfig.

tests/unit/test_cli_flags.py Outdated Show resolved Hide resolved
@jaklan
Copy link

jaklan commented Mar 19, 2024

Any updates on that?

In docs I can see:
image
but it doesn't seem to work, especially the type path is pretty confusing here.

@dbeatty10
Copy link
Contributor

Any updates on that?

it doesn't seem to work, especially the type path is pretty confusing here.

Thanks for calling this out @jaklan -- you are right, these docs will need to be updated until this PR is merged+released.

I just opened this issue to update the docs in the meantime: dbt-labs/docs.getdbt.com#5111

dbeatty10 added a commit to dbt-labs/docs.getdbt.com that referenced this pull request Mar 20, 2024
[Preview](https://docs-getdbt-com-git-dbeatty10-patch-2-dbt-labs.vercel.app/reference/global-configs/about-global-configs#available-flags)

## What are you changing in this pull request and why?

See #5111

These two things are not accurate:

1. `DBT_TARGET` won't be available until [dbt-core
#9081](dbt-labs/dbt-core#9081) is
merged+released
1. `DBT_PROFILE` won't be available until [dbt-core
#9081](dbt-labs/dbt-core#9081) is
merged+released

So this PR just removes those environment variable names until then.

## 🎩 

After the fix:

<img width="600" alt="image"
src="https://github.com/dbt-labs/docs.getdbt.com/assets/44704949/8ffdf967-604d-4686-ab4b-0e295dfea7a0">

...

<img width="600" alt="image"
src="https://github.com/dbt-labs/docs.getdbt.com/assets/44704949/0e522215-d8be-48ce-bb54-d2568e2e9479">

...

<img width="600" alt="image"
src="https://github.com/dbt-labs/docs.getdbt.com/assets/44704949/d58129d0-44c2-481e-a8bb-274fd1276c90">


## To do

- [x] Wait for #5112 to
be merged

## Checklist
- [x] Review the [Content style
guide](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/content-style-guide.md)
so my content adheres to these guidelines.
@dbeatty10 dbeatty10 self-requested a review March 21, 2024 18:51
tests/unit/test_cli.py Outdated Show resolved Hide resolved
tests/unit/test_cli.py Outdated Show resolved Hide resolved
Copy link
Contributor

@dbeatty10 dbeatty10 left a comment

Choose a reason for hiding this comment

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

Approved from a product and user experience perspective

@peterallenwebb peterallenwebb merged commit c6c0c79 into dbt-labs:main Mar 21, 2024
56 checks passed
@runleonarun runleonarun added the user docs [docs.getdbt.com] Needs better documentation label Mar 21, 2024
@FishtownBuildBot
Copy link
Collaborator

Opened a new issue in dbt-labs/docs.getdbt.com: dbt-labs/docs.getdbt.com#5134

@yu-iskw
Copy link
Contributor

yu-iskw commented Jun 3, 2024

@barton996 @dbeatty10 I have a question about the behavior of the environment variables, though the case might be an edge case. If we set DBT_TAGET and --target at the same time, DBT_TAGET is used isn't it? Personally, it would sound natural that --target can have higher priority.

$ DBT_TARGET=no_such_target dbt build --target dev 

02:46:21  Running with dbt=1.8.0
02:46:21  Encountered an error:
Runtime Error
  The profile 'jaffle_shop' does not have a target named 'no_such_target'. The valid target names for this profile are:
   - dev
   - prod

@dbeatty10
Copy link
Contributor

@yu-iskw It is supposed to use the following precedence order:

Global config precedence

dbt will pick the config in the following order (lower takes priority):

  1. user config
  2. environment variable
  3. CLI flag

i.e., if all three are provided, then the CLI flag takes precedence.

If this is not the case for target, would you be willing to open a bug report ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:yes user docs [docs.getdbt.com] Needs better documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CT-2649] [Feature] Move --target and --profile command line flags to global config
8 participants