Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/dbt_client/dbtCoreIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,9 @@ export class DBTCoreProjectIntegration
);
const { deferToProduction, manifestPath, favorState } =
await this.getDeferConfig();
await bridge.ex`project = DbtProject(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
}, 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.

}

async initializeProject(): Promise<void> {
Expand Down
Loading