Skip to content

Fix selected plans rehashing unselected external models - #6097

Draft
mday-io wants to merge 1 commit into
SQLMesh:mainfrom
mday-io:mday/preserve-unselected-external-hashes
Draft

mday-io wants to merge 1 commit into
SQLMesh:mainfrom
mday-io:mday/preserve-unselected-external-hashes

Conversation

@mday-io

@mday-io mday-io commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

Description

A selected plan can refresh schemas for a downstream model that has an unselected external co-parent. The refresh can recompute that external model's cached hash even though the model was sourced unchanged from the target environment. The plan then reports a direct external change and indirect downstream changes that were not selected.

Preserve the deployed data and metadata hashes for an unselected external model when schema refresh leaves its serialized definition unchanged. Selected external edits and selected dependency schema changes remain visible.

The regression test injects an inconsistent persisted hash to exercise this invariant. It does not claim that a normal SQLMesh migration creates that state.

Test Plan

  • Before the fix, the new regression showed the unselected external model as directly modified.
  • pytest -q tests/core/test_selector_native.py: 42 passed.
  • pytest -q tests/core/test_selector_dbt.py: 6 passed.
  • pytest -q tests/core/integration/test_plan_options.py -k test_select_models: 3 passed.
  • Ruff lint and format checks passed; git diff --check passed.
  • make style could not complete locally because this checkout lacks generated sqlmesh._version and httpx2 imports. The new test's typing errors were fixed; targeted mypy reports only the missing generated version imports.
  • make fast-test reached about 97% of its first 2,584-test group without a displayed failure, then hit a 180-second local cap. The remaining groups have not run.

Checklist

  • I have run make style and fixed any issues
  • I have added tests for my changes (if applicable)
  • All existing tests pass (make fast-test)
  • My commits are signed off (git commit -s) per the DCO

Signed-off-by: mday-io <mdaytn@gmail.com>
@mday-io
mday-io force-pushed the mday/preserve-unselected-external-hashes branch from 32bb25f to 6731332 Compare September 25, 2026 21:26
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