Skip to content

fix(context_diff): don't report metadata-only upstream changes as indirect - #6276

Open
Vamsi-klu wants to merge 1 commit into
SQLMesh:mainfrom
Vamsi-klu:fix/metadata-only-parent-changes-not-indirect
Open

Vamsi-klu wants to merge 1 commit into
SQLMesh:mainfrom
Vamsi-klu:fix/metadata-only-parent-changes-not-indirect

Conversation

@Vamsi-klu

@Vamsi-klu Vamsi-klu commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #5573.

A formatting-only change to a model's query, such as extra whitespace, still changes its data hash, because the hash includes the raw query text. The model itself is correctly categorized as a metadata change. But its children's parent_data_hash changes too, so ContextDiff.indirectly_modified reported them as "Indirectly Modified", even though they are categorized METADATA, keep their previous version, and aren't backfilled. A real metadata change, like adding an audit, doesn't list the children at all, so the two looked inconsistent.

ContextDiff.indirectly_modified now returns False for a snapshot whose parent hash changed, if it has been categorized METADATA and kept the previous version. The plan builder only assigns METADATA to an indirectly modified snapshot when every upstream change, including stored parents' changes since its previous version, is METADATA. So this matches what the plan already decided, and a real upstream data change is still reported as indirect.

The plan builder needs the raw, hash-based answer during categorization. Otherwise, rebuilding the same plan (e.g. after set_start) would see already-categorized children and flip their forward-only flag. Its three call sites pass the new include_metadata_only=True and behave exactly as before. The default is used by the display callers: the plan summary in both consoles, the CI bot and the web UI.

Out of scope: Plan.indirectly_modified, the children listed under a directly modified parent, is built separately and is unchanged. The issue's scenario, a metadata-only parent, never puts anything in it.

Test Plan

  • New integration tests in tests/core/integration/test_change_scenarios.py, on sushi:
    • test_metadata_only_parent_change_is_not_indirect: whitespace in waiter_revenue_by_day's query. The child top_waiters is not indirectly modified, is METADATA, keeps its version and has no missing intervals. It fails before the fix.
    • test_data_change_in_parent_is_indirect: a guard showing that a real change in the parent still makes the child indirectly modified.
    • test_metadata_only_parent_change_rebuild_keeps_forward_only_child: a forward-only child of a whitespace-edited parent is METADATA and forward-only after the first build, and stays so after rebuilding the same PlanBuilder. Without include_metadata_only=True, the rebuild flips the child to non-forward-only. The two categorization call sites back each other up, so the test fails only when both lose the flag. The preview filter call site isn't observable in this scenario.
  • I re-ran the reporter's sqlmesh init scenario. The child is no longer listed as indirectly modified, and its category and version are unchanged.
  • tests/core/test_plan.py, test_context.py, test_console.py, test_plan_stages.py, tests/integrations/github/cicd/, tests/core/integration/test_change_scenarios.py and test_forward_only.py: 427 passed, with no changes to existing expectations.
  • ruff format --check, ruff check and mypy on the changed files: clean.

Checklist

  • I have run make style and fixed any issues (ruff, ruff-format and mypy on the changed files)
  • I have added tests for my changes (if applicable)
  • All existing tests pass (make fast-test). I ran the affected suites listed above, not the full make fast-test.
  • My commits are signed off (git commit -s) per the DCO

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Plans now account for metadata-only changes inherited from parent models when assessing forward-only previews and classifying changes.
    • Whitespace-only query changes to a parent no longer cause unnecessary child version changes or missing-interval requirements.
    • Changes to a parent’s projections are correctly reflected as indirect changes to its child models.
    • Forward-only child models retain their metadata-only classification across repeated plan builds.

…irect

A formatting-only change to a model's query still changes its data hash,
since the hash includes the raw query text, so its children's parent
data hash changed and they were reported as indirectly modified. They
are categorized METADATA, keep their previous version and aren't
backfilled, so reporting them differs from a regular metadata change,
which doesn't list the children at all.

ContextDiff.indirectly_modified now returns False for such snapshots:
categorized METADATA with the previous version. The plan builder needs
the hash-based answer while categorizing, so that rebuilding a plan
doesn't flip forward-only flags, and opts in with
include_metadata_only=True.

Fixes SQLMesh#5573

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Vamsi-klu <nrvamsi13@gmail.com>
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

ContextDiff now distinguishes metadata-only indirect modifications from other indirect modifications. PlanBuilder includes metadata-only indirect modifications in three planning checks. Integration tests cover parent changes, child classification, missing intervals, and repeated forward-only plan builds.

Changes: Metadata-only indirect changes

Layer / File(s) Summary
Indirect modification classification
sqlmesh/core/context_diff.py, tests/core/integration/test_change_scenarios.py
ContextDiff.indirectly_modified adds the include_metadata_only option, which defaults to False. Tests cover metadata-only parent changes that preserve the child version and missing intervals, and projection changes that mark the child indirectly modified.
PlanBuilder handling
sqlmesh/core/plan/builder.py, tests/core/integration/test_change_scenarios.py
PlanBuilder includes metadata-only indirect modifications in forward-only preview selection, indirect snapshot categorization, and forward-only checks. A test checks the child’s METADATA category and forward-only status across repeated plan builds.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: izeigerman, dcohen24

Merge Risk: Minimal · up to 4c176

The change stops formatting-only parent edits from listing children as indirectly modified in plan displays. Plan building behavior is unchanged, and tests cover the main scenarios. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: ContextDiff.indirectly_modified no longer reports children as indirect when an upstream change is metadata-only. It uses the conventional fix(...) prefix, is one sente…
Description check Passed The description follows the template. It has a Description section that explains the bug, the fix, and the plan builder reasoning. It has a Test Plan section listing new integration tests and the suit…
Linked Issues check Passed Issue #5573 requires that a metadata-only parent change, such as query whitespace, does not mark its child as indirectly modified. The PR summary states that ContextDiff.indirectly_modified now retu…
Out of Scope Changes check Passed The changes are in sqlmesh/core/context_diff.py, sqlmesh/core/plan/builder.py, and tests/core/integration/test_change_scenarios.py. The context_diff.py change adds the include_metadata_only …
Full details: Title check

Explanation

The title names the main change: ContextDiff.indirectly_modified no longer reports children as indirect when an upstream change is metadata-only. It uses the conventional fix(...) prefix, is one sentence, and the changeset matches it.

Full details: Description check

Explanation

The description follows the template. It has a Description section that explains the bug, the fix, and the plan builder reasoning. It has a Test Plan section listing new integration tests and the suites run. The Checklist is present. The unchecked fast-test item is stated openly, with the reason. The required structure and information are complete.

Full details: Linked Issues check

Explanation

Issue #5573 requires that a metadata-only parent change, such as query whitespace, does not mark its child as indirectly modified. The PR summary states that ContextDiff.indirectly_modified now returns False for a snapshot whose parent hash changed when that snapshot is categorized METADATA and keeps its previous version. The default include_metadata_only=False applies to display callers. The new test test_metadata_only_parent_change_is_not_indirect covers the whitespace case and checks that the child keeps its version and has no missing intervals. A real data change still reports the child as indirect, as checked by test_data_change_in_parent_is_indirect. The PR description reports that the reporter's sqlmesh init scenario was re-run. The head file read was truncated, so the method body was not read directly. The conclusion rests on the PR summary and the described tests.

Full details: Out of Scope Changes check

Explanation

The changes are in sqlmesh/core/context_diff.py, sqlmesh/core/plan/builder.py, and tests/core/integration/test_change_scenarios.py. The context_diff.py change adds the include_metadata_only parameter that implements #5573. The builder.py change passes include_metadata_only=True at three plan-building call sites, which keeps categorization and forward-only behavior unchanged during rebuilds. The tests cover the issue scenario, a data-change guard, and forward-only rebuild behavior. The PR states that Plan.indirectly_modified is unchanged. No unrelated change is shown in the summary. The head diff tool was unavailable, so the exact hunks were not read directly.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4603844b-e438-4251-b0de-2a5eea45a537
Commits

Reviewing files that changed from the base of the PR and between ce229ae and 4c176fc.

Files selected for processing: 3

  • sqlmesh/core/context_diff.py
  • sqlmesh/core/plan/builder.py
  • tests/core/integration/test_change_scenarios.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

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.

Format change in query of parent causes child model to be classified as indirectly modified

1 participant