Skip to content

fix: rename get_incremental_microbatch_sql to capture_microbatch_compiled_code_sql#1024

Merged
GuyEshdat merged 4 commits into
masterfrom
fix/rename-microbatch-macro
Jun 18, 2026
Merged

fix: rename get_incremental_microbatch_sql to capture_microbatch_compiled_code_sql#1024
GuyEshdat merged 4 commits into
masterfrom
fix/rename-microbatch-macro

Conversation

@GuyEshdat

@GuyEshdat GuyEshdat commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Problem

Installing Elementary inadvertently broke microbatch execution for all users, even those who never set up the compiled code capture feature.

Root cause: dbt 1.9+ has two separate lookups for the get_incremental_microbatch_sql macro:

  1. Strategy execution — only searches root project + dbt-core (packages are NOT searched). This is why users need to create a root project wrapper.
  2. _microbatch_macro_is_core() check — searches ALL packages. If it finds the macro anywhere with non-Core locality, it returns False, causing use_microbatch_batches() to return False.

Because Elementary's package defined get_incremental_microbatch_sql (unprefixed), the _microbatch_macro_is_core() check found it with locality=Imported and disabled batched execution for any user with Elementary installed who hadn't set require_batched_execution_for_custom_microbatch_strategy: True — even if they weren't using the compiled code feature at all.

Our e2e tests missed this because we globally set require_batched_execution_for_custom_microbatch_strategy: True in the integration test dbt_project.yml, which bypasses the _microbatch_macro_is_core() gate entirely.

Fix

Rename the package-level macro from get_incremental_microbatch_sql to capture_microbatch_compiled_code_sql. This means:

  • Elementary no longer defines a macro with the reserved name get_incremental_microbatch_sql at the package level
  • _microbatch_macro_is_core() no longer finds Elementary's macro for users who haven't opted in → microbatch works normally
  • Users who opt in still create a root project wrapper (name unchanged: get_incremental_microbatch_sql) that calls elementary.capture_microbatch_compiled_code_sql — same behavior, no functional regression

Changes

  • macros/edr/dbt_artifacts/microbatch/capture_microbatch_compiled_code.sql: rename macro
  • integration_tests/tests/test_dbt_artifacts/test_microbatch_compiled_code.py: update call to new macro name

Breaking change

Users who already set up the compiled code feature need to update their root project macro to call elementary.capture_microbatch_compiled_code_sql instead of elementary.get_incremental_microbatch_sql. This feature is very new so we expect minimal impact. Docs PR: elementary-data/elementary (docs branch).

Summary by CodeRabbit

  • Refactor

    • Renamed the microbatch compilation macro to clearer naming that matches its capture-and-execute purpose.
    • Updated the integration test harness to use the new macro name.
  • Bug Fixes

    • Corrected the handling of compiled_code population in the “with override” scenario versus the “without override” scenario.
  • Documentation

    • Refreshed guidance explaining how to override the delegation macro for capturing microbatch compiled code.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b509ed8b-4b1a-4164-9a34-868d1961be72

📥 Commits

Reviewing files that changed from the base of the PR and between 6ced287 and 8d7858d.

📒 Files selected for processing (2)
  • integration_tests/tests/test_dbt_artifacts/test_microbatch_compiled_code.py
  • macros/edr/dbt_artifacts/microbatch/capture_microbatch_compiled_code.sql
🚧 Files skipped from review as they are similar to previous changes (1)
  • integration_tests/tests/test_dbt_artifacts/test_microbatch_compiled_code.py

📝 Walkthrough

Walkthrough

The public dbt macro get_incremental_microbatch_sql in capture_microbatch_compiled_code.sql is renamed to capture_microbatch_compiled_code_sql. The file's header documentation and the integration test's dynamically generated macro wrapper are updated to reference the new name.

Changes

Macro rename: get_incremental_microbatch_sqlcapture_microbatch_compiled_code_sql

Layer / File(s) Summary
Macro declaration, docs, and test alignment
macros/edr/dbt_artifacts/microbatch/capture_microbatch_compiled_code.sql, integration_tests/tests/test_dbt_artifacts/test_microbatch_compiled_code.py
Macro declaration renamed from get_incremental_microbatch_sql to capture_microbatch_compiled_code_sql; header documentation delegation instruction updated to match; integration test's generated override macro updated to call elementary.capture_microbatch_compiled_code_sql(arg_dict).

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐇 A macro once known by a mouthful of old,
Now answers a name that is cleaner and bold.
capture_microbatch_compiled_code_sql — hooray!
The tests and the docs all agree on the day.
One line here, one line there, and the rename is done,
A tidy little hop under the warm summer sun! ☀️

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title states 'rename get_incremental_microbatch_sql to capture_microbatch_compiled_code_sql', but the actual changes rename it to 'capture_and_execute_microbatch_compiled_code_sql', creating a mismatch between the advertised and actual macro name. Update the PR title to 'fix: rename get_incremental_microbatch_sql to capture_and_execute_microbatch_compiled_code_sql' to accurately reflect the actual macro name used in the implementation.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/rename-microbatch-macro

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown
Contributor

👋 @GuyEshdat
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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
macros/edr/dbt_artifacts/microbatch/capture_microbatch_compiled_code.sql (1)

1-49: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Commit the sqlfmt output for this macro.

CI is failing because sqlfmt rewrote this SQL file, so the checked-in version is not formatter-clean yet.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@macros/edr/dbt_artifacts/microbatch/capture_microbatch_compiled_code.sql`
around lines 1 - 49, Run sqlfmt on the capture_microbatch_compiled_code.sql file
to apply the SQL formatter's required formatting changes to both the
capture_microbatch_compiled_code_sql macro and the
capture_microbatch_compiled_code_for_model macro, then commit the formatted
output. This will ensure the checked-in version matches the formatter-clean
standards that CI expects.

Source: Pipeline failures

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@integration_tests/tests/test_dbt_artifacts/test_microbatch_compiled_code.py`:
- Line 103: Add a new test case to cover the regression scenario where
Elementary is installed without a get_incremental_microbatch_sql macro override
and without the require_batched_execution_for_custom_microbatch_strategy
behavior flag enabled. This test should either execute without the
_with_microbatch_macro_file context manager or explicitly disable the
require_batched_execution_for_custom_microbatch_strategy flag to simulate the
default-flag scenario. This ensures the original regression (which occurred in
this specific no-wrapper/default-flag configuration) is properly covered and
prevented from happening again.

---

Outside diff comments:
In `@macros/edr/dbt_artifacts/microbatch/capture_microbatch_compiled_code.sql`:
- Around line 1-49: Run sqlfmt on the capture_microbatch_compiled_code.sql file
to apply the SQL formatter's required formatting changes to both the
capture_microbatch_compiled_code_sql macro and the
capture_microbatch_compiled_code_for_model macro, then commit the formatted
output. This will ensure the checked-in version matches the formatter-clean
standards that CI expects.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1d40cc0b-e8be-4195-a039-196954e6b63b

📥 Commits

Reviewing files that changed from the base of the PR and between 88743b5 and 6ced287.

📒 Files selected for processing (2)
  • integration_tests/tests/test_dbt_artifacts/test_microbatch_compiled_code.py
  • macros/edr/dbt_artifacts/microbatch/capture_microbatch_compiled_code.sql

macro_sql = """
{% macro __MACRO_NAME__(arg_dict) %}
{{ return(elementary.get_incremental_microbatch_sql(arg_dict)) }}
{{ return(elementary.capture_microbatch_compiled_code_sql(arg_dict)) }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Inspect whether microbatch compiled-code tests cover the no-wrapper/default-flag regression path.
# Expected: at least one test path that does not enter _with_microbatch_macro_file and runs with
# require_batched_execution_for_custom_microbatch_strategy unset or explicitly False.

fd -p 'test_microbatch_compiled_code.py' -x sed -n '1,220p' {}

rg -n -C4 \
  'require_batched_execution_for_custom_microbatch_strategy|_with_microbatch_macro_file|capture_microbatch_compiled_code_sql|get_incremental_microbatch_sql' \
  --iglob '*.py' --iglob '*.yml' --iglob '*.yaml'

Repository: elementary-data/dbt-data-reliability

Length of output: 8474


🏁 Script executed:

wc -l integration_tests/tests/test_dbt_artifacts/test_microbatch_compiled_code.py

Repository: elementary-data/dbt-data-reliability

Length of output: 160


🏁 Script executed:

# Check if there are other test functions in the file
rg -n 'def test_' integration_tests/tests/test_dbt_artifacts/test_microbatch_compiled_code.py

Repository: elementary-data/dbt-data-reliability

Length of output: 140


🏁 Script executed:

# Check if the behavior flag is overridden or disabled anywhere in the test file or fixtures
rg -n 'require_batched_execution_for_custom_microbatch_strategy' integration_tests/tests/test_dbt_artifacts/ -A 3 -B 3

Repository: elementary-data/dbt-data-reliability

Length of output: 62


🏁 Script executed:

# Search for require_batched_execution_for_custom_microbatch_strategy across the entire repo
rg 'require_batched_execution_for_custom_microbatch_strategy' --type yaml --type py | head -20

Repository: elementary-data/dbt-data-reliability

Length of output: 191


🏁 Script executed:

# Check the conftest.py to see how dbt_project fixture is configured
fd -p 'conftest.py' -path '*/tests/*' -x head -100 {}

Repository: elementary-data/dbt-data-reliability

Length of output: 249


🏁 Script executed:

# Find and check conftest files
find integration_tests -name 'conftest.py' | head -5

Repository: elementary-data/dbt-data-reliability

Length of output: 116


🏁 Script executed:

# Check the entire dbt_project.yml to understand the baseline configuration
cat integration_tests/dbt_project/dbt_project.yml | grep -A 5 -B 5 'require_batched_execution_for_custom_microbatch_strategy'

Repository: elementary-data/dbt-data-reliability

Length of output: 318


🏁 Script executed:

# Check if there are any test fixtures that might disable the flag
rg 'disable.*microbatch|behavior.*flag|require_batched' integration_tests/tests/ --type py -B 3 -A 3

Repository: elementary-data/dbt-data-reliability

Length of output: 62


🏁 Script executed:

# Check the test conftest.py for any flag overrides or fixture setup
cat integration_tests/tests/conftest.py | head -150

Repository: elementary-data/dbt-data-reliability

Length of output: 4911


🏁 Script executed:

# Look for any pytest markers or parametrize that might disable the flag
rg -n 'dbt_runner|vars|disable|flags' integration_tests/tests/test_dbt_artifacts/test_microbatch_compiled_code.py

Repository: elementary-data/dbt-data-reliability

Length of output: 229


🏁 Script executed:

# Check the complete test file to see all content after line 150
tail -20 integration_tests/tests/test_dbt_artifacts/test_microbatch_compiled_code.py

Repository: elementary-data/dbt-data-reliability

Length of output: 850


🏁 Script executed:

# Check if there are any fixtures in conftest that set dbt vars or flags for microbatch tests
rg -n 'dbt_project|fixture' integration_tests/tests/conftest.py | head -30

Repository: elementary-data/dbt-data-reliability

Length of output: 974


🏁 Script executed:

# Check the dbt_project fixture definition to understand baseline setup
rg -A 30 'def dbt_project' integration_tests/tests/conftest.py

Repository: elementary-data/dbt-data-reliability

Length of output: 1077


🏁 Script executed:

# Verify the actual line 103 content in the test file to confirm the function call
sed -n '100,110p' integration_tests/tests/test_dbt_artifacts/test_microbatch_compiled_code.py

Repository: elementary-data/dbt-data-reliability

Length of output: 472


Add regression coverage for the no-wrapper/default-flag scenario.

The test currently covers two paths via _with_microbatch_macro_file: one where the macro name matches dbt's call (compiled_code populated) and one where it doesn't (compiled_code empty). However, both paths execute with a macro file present and with require_batched_execution_for_custom_microbatch_strategy set to True globally.

The original regression occurred when Elementary was installed without a get_incremental_microbatch_sql macro override AND without the behavior flag forcing batches. Add a test case that runs without entering the macro file context manager and/or with the behavior flag disabled to prevent this regression from being missed again.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@integration_tests/tests/test_dbt_artifacts/test_microbatch_compiled_code.py`
at line 103, Add a new test case to cover the regression scenario where
Elementary is installed without a get_incremental_microbatch_sql macro override
and without the require_batched_execution_for_custom_microbatch_strategy
behavior flag enabled. This test should either execute without the
_with_microbatch_macro_file context manager or explicitly disable the
require_batched_execution_for_custom_microbatch_strategy flag to simulate the
default-flag scenario. This ensures the original regression (which occurred in
this specific no-wrapper/default-flag configuration) is properly covered and
prevented from happening again.

@GuyEshdat GuyEshdat merged commit 30b0c55 into master Jun 18, 2026
30 checks passed
@GuyEshdat GuyEshdat deleted the fix/rename-microbatch-macro branch June 18, 2026 13:30
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.

2 participants