Python · Advanced · 45 min
Repair a replayed incremental load
Keep the newest version, including deletion tombstones.
Task
Repair apply_changes(state, changes). Each change has id, version, and value. A value of None is a deletion tombstone. The current implementation overwrites newer state with stale changes and mutates its input. Return a new state that is safe to replay.
Requirements
- State maps string IDs to dictionaries containing version and value. Changes use the same fields plus id.
- Keep only a strictly newer version. Equal versions are identical replays under this contract.
- Retain deletion tombstones so an old event cannot resurrect a deleted record.
- Validate every input before returning: nonempty string ID; positive integer version (not bool); value is a string or None. Invalid input raises ValueError.
- Leave both inputs unchanged, including their nested records.
IdempotencyCDCTombstonesRegression testing
Loading exercise…