Skip to content

Fix: Unexpected backfill of a parent when an interval outside the parent's range is restated for a child#5551

Merged
izeigerman merged 1 commit intomainfrom
fix-restatement-when-parent-is-outside-the-range
Oct 20, 2025
Merged

Fix: Unexpected backfill of a parent when an interval outside the parent's range is restated for a child#5551
izeigerman merged 1 commit intomainfrom
fix-restatement-when-parent-is-outside-the-range

Conversation

@izeigerman
Copy link
Collaborator

The issue might occur when the parent's start is inferred to be later (greater) than the child's and the restated interval is outside the parent's range. In this case a parent is backfilled unexpectedly.

@izeigerman izeigerman requested review from a team and Copilot October 17, 2025 23:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue where a parent model was unexpectedly backfilled when restating a child model's interval that falls outside the parent's range. The fix ensures that when a parent's start date is inferred to be later than a child's, restating intervals outside the parent's range won't trigger unnecessary parent backfills.

Key changes:

  • Modified missing_intervals() to check if the computed start date exceeds the end date before processing intervals
  • Refactored start_date() to only consider parent start dates when they exist, falling back to cron-based computation otherwise
  • Added comprehensive test coverage for the restatement edge case

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
sqlmesh/core/snapshot/definition.py Fixed logic in missing_intervals() to validate date ranges earlier and refactored start_date() to properly handle parent start date inference
tests/core/integration/test_restatement.py Added test case validating that restating a child model outside parent's date range doesn't trigger unexpected parent backfills

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

for parent in snapshot.parents
if parent in snapshots
]
earliest = (
Copy link
Contributor

Choose a reason for hiding this comment

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

in the case where a snapshot has parents it never considers its own start, shouldn't it still consider it here similar to before so have something like:

  cron_start = snapshot.node.cron_prev(snapshot.node.cron_floor(relative_to or now()))
  earliest = min([cron_start] + parent_starts) if parent_starts else cron_start

Copy link
Contributor

Choose a reason for hiding this comment

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

actually I see now this is needed to constrain the data of the child to avoid the backfill of parents

@izeigerman izeigerman force-pushed the fix-restatement-when-parent-is-outside-the-range branch from 87161bd to dd25a56 Compare October 20, 2025 19:03
@izeigerman izeigerman merged commit d7d6f0b into main Oct 20, 2025
28 checks passed
@izeigerman izeigerman deleted the fix-restatement-when-parent-is-outside-the-range branch October 20, 2025 19:48
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.

3 participants