Skip to content

Fix Execute SQL target #1685

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

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

Conversation

anandgupta42
Copy link
Contributor

@anandgupta42 anandgupta42 commented Jun 9, 2025

Summary

  • ensure python project uses the selected target when executing SQL

fix for #1676

Testing

  • npm test

Important

Fixes bug in createPythonDbtProject() to ensure correct target is used when executing SQL in dbtCoreIntegration.ts.

  • Bug Fix:
    • In dbtCoreIntegration.ts, createPythonDbtProject() now includes target_name parameter to ensure correct target is used when executing SQL.
  • Testing:
    • Verified with npm test.

This description was created by Ellipsis for 12c4ef5. You can customize this summary. It will automatically update as commits are pushed.


Summary by CodeRabbit

  • Bug Fixes
    • Improved project initialization to ensure the correct target environment is explicitly set during operations.

Copy link
Contributor

coderabbitai bot commented Jun 9, 2025

Walkthrough

The change updates the internal implementation of the createPythonDbtProject method within the DBTCoreProjectIntegration class to include the target_name parameter when instantiating the Python DbtProject object. No public interfaces or exported declarations are altered.

Changes

File(s) Change Summary
src/dbt_client/dbtCoreIntegration.ts Passes target_name (from targetName property) to the Python DbtProject constructor in a method.

Sequence Diagram(s)

sequenceDiagram
    participant JS as DBTCoreProjectIntegration (TypeScript)
    participant Py as Python DbtProject

    JS->>Py: Instantiate DbtProject(project_dir, profiles_dir, target_path, defer_to_prod, manifest_path, favor_state, target_name)
    Py-->>JS: Returns DbtProject instance with target_name set
Loading

Suggested reviewers

  • anandgupta42
  • saravmajestic

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-06-16T12_43_55_563Z-debug-0.log


📜 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 6bb7097 and 12c4ef5.

📒 Files selected for processing (1)
  • src/dbt_client/dbtCoreIntegration.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/dbt_client/dbtCoreIntegration.ts
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: test (macos-latest)
  • GitHub Check: test (ubuntu-latest)
  • GitHub Check: test (windows-latest)
  • GitHub Check: build (windows-latest)
  • GitHub Check: Analyze (javascript-typescript)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

@anandgupta42 anandgupta42 requested a review from Copilot June 9, 2025 01:08
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses the issue in executing SQL by ensuring the Python project uses the selected target when creating a DbtProject instance.

  • Fixes the DbtProject constructor call to include the proper target_name parameter.
  • Updates the code in DBTCoreProjectIntegration to use this.targetName when invoking createPythonDbtProject().
Comments suppressed due to low confidence (1)

src/dbt_client/dbtCoreIntegration.ts:473

  • Verify that the DbtProject constructor accepts 'target_name' as a parameter and that its positional order aligns with the intended API design. Consider adding inline documentation if the parameter order is significant.
await bridge.ex`project = DbtProject(target_name=${this.targetName}, project_dir=${this.projectRoot.fsPath}, profiles_dir=${this.profilesDir}, target_path=${targetPath}, defer_to_prod=${deferToProduction}, manifest_path=${manifestPath}, favor_state=${favorState}) if 'project' not in locals() else project`

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.

Important

Looks good to me! 👍

Reviewed everything up to 69eeccd in 1 minute and 23 seconds. Click for details.
  • Reviewed 15 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. src/dbt_client/dbtCoreIntegration.ts:473
  • Draft comment:
    Good change – you now pass the selected target (target_name) when instantiating DbtProject, ensuring SQL execution uses the chosen target. However, ensure that this.targetName is set (i.e., not undefined) before calling createPythonDbtProject. If it might be undefined, consider adding a check or fallback to avoid potential issues.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% The comment is about a real code change - adding target_name parameter. However, the suggestion to validate this.targetName is speculative since we don't know if undefined is a valid value for the Python DbtProject constructor. The comment is asking for confirmation/verification rather than pointing out a clear issue. The code may work fine with undefined being passed through. I could be wrong about whether undefined would cause issues in the Python bridge layer. Perhaps there's a real risk of errors if undefined is passed through. Even if undefined could cause issues, the comment is still phrased as a verification request rather than pointing out a clear problem. If undefined was definitely problematic, the comment should directly state that and suggest a specific fix. The comment should be deleted because it is speculative and asks for verification rather than identifying a clear issue that needs to be fixed.

Workflow ID: wflow_D3rPHobRFo5iHOoB

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@anandgupta42 anandgupta42 requested a review from mdesmet June 9, 2025 01:09
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 449c9b2 and 6bb7097.

📒 Files selected for processing (1)
  • src/dbt_client/dbtCoreIntegration.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build (windows-latest)
  • GitHub Check: test (windows-latest)

Comment on lines 473 to 475
await bridge.ex`project = DbtProject(target_name=${
this.targetName
}, project_dir=${this.projectRoot.fsPath}, profiles_dir=${this.profilesDir}, target_path=${targetPath}, defer_to_prod=${deferToProduction}, manifest_path=${manifestPath}, favor_state=${favorState}) if 'project' not in locals() else project`;
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Fix potential undefined target_name during initialization.

The addition of target_name parameter correctly addresses the PR objective of using the selected target for SQL execution. However, there's a critical issue: this.targetName can be undefined during the initial call to createPythonDbtProject() in initializeProject() (line 503), since refreshProjectConfig() (which sets this.targetName) hasn't been called yet.

Apply this diff to handle the undefined case:

-    await bridge.ex`project = DbtProject(target_name=${
-      this.targetName
-    }, project_dir=${this.projectRoot.fsPath}, profiles_dir=${this.profilesDir}, target_path=${targetPath}, defer_to_prod=${deferToProduction}, manifest_path=${manifestPath}, favor_state=${favorState}) if 'project' not in locals() else project`;
+    await bridge.ex`project = DbtProject(target_name=${
+      this.targetName || null
+    }, project_dir=${this.projectRoot.fsPath}, profiles_dir=${this.profilesDir}, target_path=${targetPath}, defer_to_prod=${deferToProduction}, manifest_path=${manifestPath}, favor_state=${favorState}) if 'project' not in locals() else project`;

Verify how the Python DbtProject constructor handles null target_name:


🏁 Script executed:

#!/bin/bash
# Description: Find the Python DbtProject constructor to verify parameter handling

# Search for DbtProject class definition and constructor
ast-grep --pattern $'class DbtProject:
  $$$
  def __init__($$$):
    $$$'

# Also search for target_name parameter usage
rg -A 10 -B 5 "target_name.*=" --type py

Length of output: 39378


Guard against undefined targetName in createPythonDbtProject.

To prevent passing undefined (which the Python bridge may not handle) into the DbtProject constructor—which expects an Optional[str]—we should fall back to null so Python receives None.

Locations to update:

  • File: src/dbt_client/dbtCoreIntegration.ts
  • Method: createPythonDbtProject()
  • Around lines 473–475

Suggested diff:

-    await bridge.ex`project = DbtProject(target_name=${
-      this.targetName
-    }, project_dir=${this.projectRoot.fsPath}, profiles_dir=${this.profilesDir}, target_path=${targetPath}, defer_to_prod=${deferToProduction}, manifest_path=${manifestPath}, favor_state=${favorState}) if 'project' not in locals() else project`;
+    await bridge.ex`project = DbtProject(target_name=${
+      this.targetName ?? null
+    }, project_dir=${this.projectRoot.fsPath}, profiles_dir=${this.profilesDir}, target_path=${targetPath}, defer_to_prod=${deferToProduction}, manifest_path=${manifestPath}, favor_state=${favorState}) if 'project' not in locals() else project`;

This uses the nullish coalescing operator (??) to ensure that when this.targetName is undefined, the Python side sees None.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
await bridge.ex`project = DbtProject(target_name=${
this.targetName
}, project_dir=${this.projectRoot.fsPath}, profiles_dir=${this.profilesDir}, target_path=${targetPath}, defer_to_prod=${deferToProduction}, manifest_path=${manifestPath}, favor_state=${favorState}) if 'project' not in locals() else project`;
await bridge.ex`project = DbtProject(target_name=${
this.targetName ?? null
}, project_dir=${this.projectRoot.fsPath}, profiles_dir=${this.profilesDir}, target_path=${targetPath}, defer_to_prod=${deferToProduction}, manifest_path=${manifestPath}, favor_state=${favorState}) if 'project' not in locals() else project`;
🤖 Prompt for AI Agents
In src/dbt_client/dbtCoreIntegration.ts around lines 473 to 475, the code passes
this.targetName directly to the Python DbtProject constructor, but
this.targetName can be undefined during initial calls. To fix this, update the
code to use the nullish coalescing operator (??) to pass null instead of
undefined when this.targetName is not set, ensuring the Python side receives
None and preventing errors.

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.

Important

Looks good to me! 👍

Reviewed 12c4ef5 in 1 minute and 0 seconds. Click for details.
  • Reviewed 15 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. src/dbt_client/dbtCoreIntegration.ts:470
  • Draft comment:
    The revised template literal now inlines the interpolation for target_name (i.e. ${this.targetName}) without a newline, ensuring the correct target is passed to the DbtProject constructor. This concise formatting helps avoid unintended whitespace which might have caused the Execute SQL target issue.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% This comment is purely informative, explaining the change made in the code. It doesn't provide any actionable feedback or suggestions for improvement. It doesn't align with the rules for useful comments.

Workflow ID: wflow_uQgqpeH4n96jDdaJ

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@mdesmet
Copy link
Contributor

mdesmet commented Jun 16, 2025

Tested this change but this is a no-op. This line is only executed once at init time:

Instantiates a DbtProject object with the given parameters if project is not already defined in the local scope.

Otherwise, it reuses the existing project object (avoiding re-instantiation).

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

Successfully merging this pull request may close these issues.

2 participants