feat: add "Execute dbt Model" command (#1875) - #1894
Conversation
Adds `dbtPowerUser.executeModel` as a sibling to the existing `executeSQL` command. Bound to `Cmd+Shift+Enter` / `Ctrl+Shift+Enter`, invokes `dbt show --select <model>` via the new `executeModel` API in `@altimateai/dbt-integration` so `selected_resources` is populated and packages like `upstream-prod` work correctly. Existing `Cmd+Enter` (`executeSQL`, `--inline`) is unchanged — iteration, highlighted-fragment execution, and ad-hoc query panel all continue to work as before. Surfaces mirrored from `executeSQL`: command palette entry, editor title toolbar (navigation@2, `$(play-circle)` icon), keybinding. The query panel webview renders the result unchanged because `executeModel` produces the same `QueryExecution` shape. Validation / error surfaces (done at invocation time, not hidden via `when` clauses, to avoid dependency on manifest membership): - Untitled / no-project file: error toast pointing to Execute Query. - Python-bridge mode: `NotImplementedError` from the integration is caught and surfaced as a toast directing users to switch to `corecommand`, `cloud`, or `fusion`. Depends on AltimateAI/altimate-dbt-integration#52 (upstream API). Dep version in `package.json` will bump from `^0.2.13` to the released version after #52 merges. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Execute SQL previews the editor contents as an anonymous node, so Jinja that reads `model.name`, `this`, or `model.config` resolves to a placeholder and the model fails to compile. Execute dbt Model previews the file as its real node, but nothing tells the user it exists at the moment they need it. When an inline preview fails to compile, append a hint naming that command. The detection only decides whether to show a sentence, never how the query runs, so a wrong guess costs a line of text rather than wrong results. Gated on all of: - the whole saved file was previewed — not a selection, not unsaved edits, where the editor contents are the point and `--select` would run something different - the file resolves to a real node in the manifest - the integration implements the command; Python-bridge mode throws NotImplementedError The hint names the command rather than its keybinding: the chord differs per platform and users can rebind it.
Docker E2E — full flow through the extensionRe-run end to end on the current branch (the earlier E2E note predated the hint and the rebase onto master, so it has been replaced). Verified the whole chain: keybinding → command handler → integration adapter → CLI invocation → dbt runtime → query panel. Setup
1. Before — the failure users actually hit
2. After — the real error, plus the way outSame keystroke, same file, this branch: The actual dbt error surfaces ( Note the heading reads 3. The command the hint points at works
4. The hint stays quiet when it would be wrongSelecting only line 1 and pressing Status bar shows 5.
|
|
Superseded by #2055. This PR added an opt-in #2055 is built fresh on |




Closes #1875.
Problem
Execute SQLpreviews the editor contents withdbt show --inline, which compiles the SQL as an anonymous node (inline_<hash>). Any Jinja that reads the current node's identity —model.name,this,model.config, or a macro derived from them — therefore resolves against a placeholder rather than the model in front of you.Two symptoms, same cause:
upstream-prod):--inlineleavesselected_resourcesempty, so packages reading it misbehave.dbt show --inlineloses node identity — models using model.name-dependent macros fail with "Could not find previewLine in" #2028: a model whose macro asserts onmodel.namefails to compile, and the user sees an unreadable error.--inlineis the right thing for a highlighted fragment or an unsaved edit — there is no real node to point dbt at. It is the wrong thing for a saved model file, and dbt offers no way to have both: there is no--as-node <name>for inline SQL.Change
1. A second, opt-in command.
Execute dbt Model(Ctrl/Cmd+Shift+Enter) previews the file as its real node viadbt show --select <model>.Execute SQL(Ctrl/Cmd+Enter) is unchanged and still uses--inline.Deliberately opt-in rather than auto-routing: pressing a different key is the user declaring intent, so nothing has to be inferred. Auto-detection was considered and rejected —
getQuery()returns the selection when one exists, so highlighting a CTE insidestg_orders.sqlyieldsmodelName="stg_orders"with fragment SQL. Auto-routing there would silently run the whole model and return rows the user never asked for, with no error at all — strictly worse than today's loud failure. Two of the fourexecuteSQLcall sites also pass synthetic names ("cte_query",cte_<name>_<hash>).2. A hint, so the command is discoverable at the moment it's needed. The opt-in design's one weakness is that nobody finds it. When an inline preview fails to compile, the error now carries a line naming the command. Detection gates a sentence, never behaviour, so a false positive costs a line of text rather than wrong results.
Shown only when all of these hold:
NotImplementedError, so no hint there)The hint names the command rather than its keybinding: the chord differs per platform and users can rebind it.
Verified end to end
Built and driven in code-server against a dbt project whose macro asserts on
model.name, on thecorecommandpath (which shares--inlineand was the worse of the two — it previously died with a bareTypeError):TypeError: Cannot read properties of undefined (reading 'data')Model 'inline_query' must start with stg_ … Hint: … use the "Execute dbt Model" command.Execute dbt Model: returnsnode_name = stg_identity_probe— identity preserved, macro passes, real rowsEnd-to-end verification also caught a defect that no unit test would have: setting
Error.namemade the query panel renderInlinePreviewCompilationError:as the user-facing heading. Fixed library-side and re-verified.Merge order — this PR is blocked
The extension side compiles only against an unreleased library. CI fails with:
Expected, not a regression. It needs, in order:
executeModelAPI and the inline compile-error surfacing (both halves, consolidated into that one PR)@altimateai/dbt-integrationrelease, and the version bump hereUntil then this stays draft and red. Verified locally against a build of that branch: typecheck clean, 638 tests passing.
Tests
7 new unit tests covering the gate and the wrapper: hint offered for a saved unedited model; suppressed for a selection, for unsaved edits, for Python-bridge mode, and for a file that is not a manifest node; hint appended to an inline compile failure; unrelated errors passed through untouched; successful results unaffected.