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

fix: resolve DBT_PROFILES_DIR correctly if relative path specified #1573

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

diegoquintanav
Copy link

@diegoquintanav diegoquintanav commented Feb 6, 2025

Overview

Problem

if DBT_PROFILES_DIR is set, then

return os.path.normpath(os.path.join(project_dir, profiles_dir))

is joining project_dir with profiles_dir. If project_dir is coming from DBT_PROJECT_DIR, and both paths are relative then this is effectively producing <DBT_PROJECT_DIR>/<DBT_PROFILES_DIR> which may not exist.

In my case, I have

DBT_PROJECT_DIR=my_project
DBT_PROFILES_DIR=my_project/my_profiles

and this method is returning default_profiles_dir=my_project/my_project/my_profiles

The value of project_dir being passed is resolved as **/dbt_project.yml as in

`**/${DBTProject.DBT_PROJECT_FILE}`,

see #1554 (comment) for the original reply

Closes #1554

Solution

Removing the unnecessary path join

Screenshot/Demo

A picture is worth a thousand words. Please highlight the changes if applicable.

How to test

  • Steps to be followed to verify the solution or code changes
  • Mention if there is any settings configuration added/changed/deleted

Checklist

  • I have run this code and it appears to resolve the stated issue
  • README.md updated and added information about my change

Important

Fixes path resolution in default_profiles_dir() by removing unnecessary path joining with project_dir when DBT_PROFILES_DIR is set.

  • Behavior:
    • Fixes path resolution in default_profiles_dir() in dbt_core_integration.py by removing unnecessary os.path.join with project_dir when DBT_PROFILES_DIR is set.
    • Ensures DBT_PROFILES_DIR is used as is if it's an absolute path, or resolved correctly if relative.
  • Misc:

This description was created by Ellipsis for d3864a8. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • Refactor
    • Updated the resolution method for profile directories, allowing for direct use of custom configuration values.
    • This change may impact scenarios involving relative paths in configuration settings.

Copy link
Contributor

coderabbitai bot commented Feb 6, 2025

Walkthrough

This pull request modifies the default_profiles_dir function in dbt_core_integration.py. Instead of joining the project directory with the DBT_PROFILES_DIR environment variable value, the function now returns the normalized path of the DBT_PROFILES_DIR value alone. No other code sections were altered.

Changes

File(s) Change Summary
dbt_core_integration.py Updated the default_profiles_dir function: changed its return from joining project_dir with profiles_dir to returning the normalized path of profiles_dir alone.

Assessment against linked issues

Objective Addressed Explanation
Correctly resolve and use the DBT profiles directory from the environment (.env) file (#1554)

Possibly related PRs

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d3864a8 and ee8e010.

📒 Files selected for processing (1)
  • dbt_core_integration.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • dbt_core_integration.py

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

❌ Changes requested. Reviewed everything up to d3864a8 in 56 seconds

More details
  • Looked at 13 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. dbt_core_integration.py:220
  • Draft comment:
    Nice fix. The unnecessary join with project_dir has been removed for relative DBT_PROFILES_DIR paths. Consider simplifying further by returning os.path.normpath(profiles_dir) directly, since os.path.join with a single argument is redundant.
  • Reason this comment was not posted:
    Marked as duplicate.

Workflow ID: wflow_Dpk2RzYw2qB4JPf1


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

dbt_core_integration.py Outdated Show resolved Hide resolved
@diegoquintanav diegoquintanav changed the title fix: resolve to DBT_PROFILES_DIR if specified without joining with project_dir fix: resolve DBT_PROFILES_DIR correctly if relative path specified Feb 6, 2025
@mdesmet
Copy link
Contributor

mdesmet commented Feb 6, 2025

This change will break things for other people.For the extension the CWD is not obvously set, compared to CLI where there is clear concept of CWD. Becasue of that we went with choosing the project directory as the CWD.

@anandgupta42
Copy link
Contributor

@diegoquintanav I am not sure how this resolves the original bug #1554 . Can you help explain?

@diegoquintanav
Copy link
Author

diegoquintanav commented Feb 6, 2025

This change will break things for other people.For the extension the CWD is not obvously set, compared to CLI where there is clear concept of CWD. Becasue of that we went with choosing the project directory as the CWD.

Hey thanks for checking this PR!

This change affects only the scenario where DBT_PROFILES_DIR is set as an environment variable and is not an absolute path. I've pasted my original reply to the issue in the PR description if that helps.

In what cases would you say it breaks behaviour for other people?

@mdesmet
Copy link
Contributor

mdesmet commented Feb 10, 2025

In the code that is removed in this PR the path is relative to the project root. In your case it is to be defined, by the calling code (probably the first workspace root directory). All people that have setup a relative path from the project root would have an issue if we merge this.

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.

Extension not picking up env variables from .env file
3 participants