Fix: Unexpected backfill of a parent when an interval outside the parent's range is restated for a child#5551
Conversation
There was a problem hiding this comment.
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 = ( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
actually I see now this is needed to constrain the data of the child to avoid the backfill of parents
…ent's range is restated for a child
87161bd to
dd25a56
Compare
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.