Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Use the same logic as dbt-core for the path for the project and profiles #415

Merged
merged 14 commits into from
Mar 10, 2023

Conversation

dbeatty10
Copy link
Contributor

@dbeatty10 dbeatty10 commented Feb 25, 2023

resolves #416

Overview

The changes in this PR allow using the same logic as dbt. The precedence for the location of profiles.yml changed starting dbt-core>=1.4.0.

This PR is designed to determine the version of dbt indicated within the manifest and use the applicable logic.

Behavior for dbt >= 1.3

The parent directory for profiles.yml is determined using the following precedence:

  1. --profiles-dir option (--dbt-profiles-dir in data-diff)
  2. DBT_PROFILES_DIR environment variable
  3. current working directory ← NEW
  4. ~/.dbt/ directory

Behavior prior to 1.3:

The parent directory for profiles.yml is determined using the following precedence:

  1. --profiles-dir option (--dbt-profiles-dir in data-diff)
  2. DBT_PROFILES_DIR environment variable
  3. ~/.dbt/ directory

Both are documented here. The version needs to be changed at the top of the screen to switch between versions.

image

Implementation details

Path is used liberally.

Source of the logic

The relevant logic is located here in dbt-core:

@dbeatty10 dbeatty10 marked this pull request as ready for review February 25, 2023 03:02
@dbeatty10
Copy link
Contributor Author

@erezsh I made an attempt to update the mocks so that they are Paths rather than strs.

If someone is willing to re-run the CI workflows, we can see if that worked or not.

@dbeatty10
Copy link
Contributor Author

I'm getting this error, so I'll just need to look at the way the test is expressed and update the test accordingly:

Expected: open('target/run_results.json')
Actual: open(PosixPath('target/run_results.json'))

Alternatively, I could cast all the Paths to strs and the tests should pass. But it seems like using a Path in open should be acceptable.

@dlawin
Copy link
Contributor

dlawin commented Feb 28, 2023

I'm getting this error, so I'll just need to look at the way the test is expressed and update the test accordingly:

Expected: open('target/run_results.json')
Actual: open(PosixPath('target/run_results.json'))

Alternatively, I could cast all the Paths to strs and the tests should pass. But it seems like using a Path in open should be acceptable.

yeah I should have used Path originally

@dlawin
Copy link
Contributor

dlawin commented Mar 1, 2023

This is dbt's behavior only as of >=1.4 correct?

Just worried we cause a disconnect for dbt < 1.4

@dlawin
Copy link
Contributor

dlawin commented Mar 4, 2023

This is dbt's behavior only as of >=1.4 correct?

Just worried we cause a disconnect for dbt < 1.4

I think we should make this change and align with dbt, but I do think we should also consider how to handle <1.4

The shift of this default location was a little jarring for dbt users, and anecdotally I've seen many work around the change via the environment variable export DBT_PROFILES_DIR=~/.dbt/

If we had a data-diff --dbt-debug feature analogous to dbt debug, or were a little more verbose when starting a data-diff --dbt, I'd feel a little more comfortable about it.

The location of this file is a little chaotic at the moment, and the <dbt_project>/profiles.yml file will often have {{env_var()}}s that are not set on local dev environments. With --dbt's current state, there could be some very obscure errors. Ironically, I think those on 1.4+ are more aware of this location being a potential issue than those who aren't

@dbeatty10
Copy link
Contributor Author

Agreed that it makes sense to align with the behavior based on the dbt version.

I just pushed some changes to try handling both the DBT_PROFILES_DIR environment variable as well as the change in behavior between dbt 1.2 and dbt 1.3.

⚠️ I did not test them locally yet though.

Behavior for dbt >= 1.3

The parent directory for profiles.yml is determined using the following precedence:

  1. --profiles-dir option
  2. DBT_PROFILES_DIR environment variable
  3. current working directory
  4. ~/.dbt/ directory

Behavior prior to 1.3:

The parent directory for profiles.yml is determined using the following precedence:

  1. --profiles-dir option
  2. DBT_PROFILES_DIR environment variable
  3. ~/.dbt/ directory

Both are documented here. The version needs to be changed at the top of the screen to switch between versions.

image

Copy link
Contributor

@dlawin dlawin left a comment

Choose a reason for hiding this comment

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

Works great, really appreciate the contributions Doug!

@dlawin dlawin merged commit 5f56d9f into datafold:master Mar 10, 2023
@dbeatty10
Copy link
Contributor Author

Like the wording update @dlawin -- thanks for putting that in there 🏅

@williebsweet
Copy link
Contributor

Thanks, @dbeatty10!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use the same logic as dbt-core or the paths for the project and profiles
4 participants