Skip to content

Support dbt Fusion#840

Closed
kverburg wants to merge 4 commits into
elementary-data:masterfrom
kverburg:fix-support-fusion
Closed

Support dbt Fusion#840
kverburg wants to merge 4 commits into
elementary-data:masterfrom
kverburg:fix-support-fusion

Conversation

@kverburg
Copy link
Copy Markdown

@kverburg kverburg commented Aug 11, 2025

To tackle this issue.

Note on the on-run-start/end part: I don't really like the solution. Trouble is that this method will fire a query at the database. In Core this was failing silently, but in Fusion you will get an explicit error. A better solution would be to run an operation on at the start/end, but I don't think we can do that.

Summary by CodeRabbit

  • New Features
    • Run start and end hooks now return simple SQL statements, improving visibility and compatibility with downstream tooling.
  • Chores
    • Updated ignore list to exclude package-lock.yml, .venv/, and dbt_internal_packages/.
    • Relocated deprecation metadata for compiled_sql in the run results model to config.meta for consistency.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Aug 11, 2025

Walkthrough

Adds new ignore patterns to .gitignore. Modifies dbt hook macros to return simple SQL strings at run start and end. Updates models/run_results.yml to relocate deprecation metadata for compiled_sql from a top-level meta block into config.meta in two locations.

Changes

Cohort / File(s) Change Summary
Repository ignore rules
/.gitignore
Added ignore entries: package-lock.yml, .venv/, dbt_internal_packages/.
DBT hooks return SQL
macros/edr/system/hooks/on_run_start.sql, macros/edr/system/hooks/on_run_end.sql
on_run_start now returns select 'on-run-start'; on_run_end appends a dummy_query and returns it (select 'on-run-end'). Macro signatures unchanged; existing logic preserved.
Run results model meta relocation
models/run_results.yml
Moved deprecated_columns entry for compiled_sql from top-level meta to config.meta (applied in two places). Content unchanged.

Sequence Diagram(s)

sequenceDiagram
  participant Dbt as dbt runtime
  participant Hook as on_run_start macro

  Dbt->>Hook: Invoke on_run_start
  Hook->>Hook: Perform existing setup logic
  Hook-->>Dbt: Return SQL: select 'on-run-start'
Loading
sequenceDiagram
  participant Dbt as dbt runtime
  participant Hook as on_run_end macro

  Dbt->>Hook: Invoke on_run_end
  Hook->>Hook: Perform existing cleanup/upload logic
  Hook-->>Dbt: Return SQL: select 'on-run-end'
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

I thump my paws at pipeline’s end,
A start, a stop—two queries send.
Ignored the clutter, neat and light,
Meta moved to where it’s right.
With whiskered nods I sign and yield—
Run begins, run ends, all sealed. 🐇✨

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
  • 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.

Support

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

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 generate unit tests to generate unit tests for 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.

@github-actions
Copy link
Copy Markdown
Contributor

👋 @kverburg
Thank you for raising your pull request.
Please make sure to add tests and document all user-facing changes.
You can do this by editing the docs files in the elementary repository.

Copy link
Copy Markdown

@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

🧹 Nitpick comments (1)
macros/edr/system/hooks/on_run_end.sql (1)

39-44: Clarify when to emit dummy SQL; consider scoping under execute/docs condition

Currently, dummy_query is always returned even when execute is false or the command is docs (the internal work is skipped, but the SELECT still returns). If Fusion requires a SQL return only in execute runs, move the return inside the same condition and return '' otherwise.

-{% set dummy_query %}
-  -- This query is needed for Elementary to work correctly with dbt Fusion
-  select 'on-run-end'
-{% endset %}
-{{ return(dummy_query) }}
+{% if execute and not elementary.is_docs_command() %}
+  {% set dummy_query %}
+  -- This query is needed for Elementary to work correctly with dbt Fusion
+  select 'on-run-end'
+  {% endset %}
+  {{ return(dummy_query) }}
+{% else %}
+  {{ return('') }}
+{% endif %}

Additionally, the inner condition checks “not execute” even though the outer guard already ensures execute is true; that part is unreachable and can be dropped for clarity. Want a patch for that too?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between eda3219 and 931ecd5.

📒 Files selected for processing (4)
  • .gitignore (3 hunks)
  • macros/edr/system/hooks/on_run_end.sql (1 hunks)
  • macros/edr/system/hooks/on_run_start.sql (1 hunks)
  • models/run_results.yml (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-07-15T19:31:54.689Z
Learnt from: haritamar
PR: elementary-data/dbt-data-reliability#825
File: models/run_results.yml:139-145
Timestamp: 2025-07-15T19:31:54.689Z
Learning: In dbt-fusion (dbt 2.0+), the `meta` configuration for models should be nested under the `config` block (i.e., `config: meta:`), not as a top-level `meta` key. This is different from traditional dbt where `meta` was a sibling of `config`.

Applied to files:

  • models/run_results.yml
🔇 Additional comments (4)
.gitignore (3)

15-15: Good addition: cover virtualenvs with .venv/

This complements venv/ and avoids accidental commits of local envs.


29-29: Good addition: ignore dbt_internal_packages/

Prevents committing dbt’s internal dependencies; aligns with dbt Fusion/dbt Core behaviors.


5-5: Typo? Use package-lock.json instead of package-lock.yml

Node’s lockfile is package-lock.json. If the intent is to ignore the Node lockfile, update accordingly.

-package-lock.yml
+package-lock.json
⛔ Skipped due to learnings
Learnt from: haritamar
PR: elementary-data/dbt-data-reliability#825
File: package-lock.yml:1-5
Timestamp: 2025-07-15T19:28:12.728Z
Learning: The correct filename for dbt's lockfile is `package-lock.yml`, not `packages.lock`. The `dbt deps` command generates and uses `package-lock.yml` to lock dependency versions.
Learnt from: haritamar
PR: elementary-data/dbt-data-reliability#825
File: package-lock.yml:1-5
Timestamp: 2025-07-15T19:28:12.728Z
Learning: The correct filename for dbt's lockfile is `package-lock.yml`, not `packages.lock`. The `dbt deps` command generates and uses `package-lock.yml` to lock dependency versions. This is the official and documented filename as of dbt v1.7 and onward.
models/run_results.yml (1)

139-144: All dbt_run_results entries use config.meta correctly

I searched for other instances of name: dbt_run_results in models/run_results.yml and found only the single definition at lines 133–144, which already nests deprecated_columns under config.meta. No further changes are needed.

Comment on lines 22 to 27
{% if elementary.is_test_command() %}
{{ elementary.create_elementary_tests_schema() }}
{% endif %}

{{ return("select 'on-run-start'") }}
{% endmacro %}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Risk: final return likely discards earlier emitted SQL (tests schema creation)

Using {{ return("select 'on-run-start'") }} at the end can override any previously rendered SQL (e.g., {{ elementary.create_elementary_tests_schema() }}), so the schema creation may no longer run in test commands.

Refactor to collect statements and return them together to preserve behavior.

-  {% if elementary.is_test_command() %}
-    {{ elementary.create_elementary_tests_schema() }}
-  {% endif %}
-
-  {{ return("select 'on-run-start'") }}
+  {# Collect hook SQLs to ensure nothing is lost when returning #}
+  {% set hook_sqls = [] %}
+  {% if elementary.is_test_command() %}
+    {% set _create_sql %}{{ elementary.create_elementary_tests_schema() }}{% endset %}
+    {% do hook_sqls.append(_create_sql) %}
+  {% endif %}
+  {% do hook_sqls.append("select 'on-run-start'") %}
+  {{ return(hook_sqls | join(';\n')) }}
📝 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
{% if elementary.is_test_command() %}
{{ elementary.create_elementary_tests_schema() }}
{% endif %}
{{ return("select 'on-run-start'") }}
{% endmacro %}
{# Collect hook SQLs to ensure nothing is lost when returning #}
{% set hook_sqls = [] %}
{% if elementary.is_test_command() %}
{% set _create_sql %}{{ elementary.create_elementary_tests_schema() }}{% endset %}
{% do hook_sqls.append(_create_sql) %}
{% endif %}
{% do hook_sqls.append("select 'on-run-start'") %}
{{ return(hook_sqls | join(';\n')) }}
{% endmacro %}
🤖 Prompt for AI Agents
In macros/edr/system/hooks/on_run_start.sql around lines 22 to 27, the final {{
return("select 'on-run-start'") }} will overwrite any previously emitted SQL
(such as the elementary.create_elementary_tests_schema() call) causing the tests
schema creation to be discarded; change the macro to accumulate statements
(e.g., push the conditional schema-creation SQL into a list or a buffer
variable) and then return a single concatenated string that includes both the
schema creation SQL (when applicable) and the "select 'on-run-start'" statement
so earlier emitted SQL is preserved.

@kverburg kverburg had a problem deploying to elementary_test_env August 11, 2025 08:22 — with GitHub Actions Failure
@kverburg kverburg had a problem deploying to elementary_test_env August 11, 2025 08:22 — with GitHub Actions Failure
@kverburg kverburg had a problem deploying to elementary_test_env August 11, 2025 08:22 — with GitHub Actions Failure
@kverburg kverburg had a problem deploying to elementary_test_env August 11, 2025 08:22 — with GitHub Actions Failure
@kverburg kverburg had a problem deploying to elementary_test_env August 11, 2025 08:22 — with GitHub Actions Failure
@kverburg kverburg had a problem deploying to elementary_test_env August 11, 2025 08:22 — with GitHub Actions Failure
@kverburg kverburg had a problem deploying to elementary_test_env August 11, 2025 08:22 — with GitHub Actions Failure
@kverburg kverburg had a problem deploying to elementary_test_env August 11, 2025 08:22 — with GitHub Actions Failure
@kverburg kverburg had a problem deploying to elementary_test_env August 11, 2025 08:22 — with GitHub Actions Failure
@kverburg kverburg had a problem deploying to elementary_test_env August 11, 2025 08:22 — with GitHub Actions Failure
@kverburg kverburg had a problem deploying to elementary_test_env August 11, 2025 08:22 — with GitHub Actions Failure
@kverburg kverburg closed this Aug 11, 2025
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.

1 participant