@@ -623,3 +623,39 @@ def test_disable_restatement(make_snapshot, mocker: MockerFixture):
623623 # Restatements should still be supported when in dev.
624624 plan = Plan (context_diff_mock , is_dev = True , restate_models = ["a" ])
625625 assert plan .restatements == {"a" }
626+
627+
628+ def test_revert_to_previous_value (make_snapshot , mocker : MockerFixture ):
629+ """
630+ Make sure we can revert to previous snapshots with intervals if it already exists and not modify
631+ it's existing change category
632+ """
633+ old_snapshot_a = make_snapshot (
634+ SqlModel (name = "a" , query = parse_one ("select 1, ds" ), depends_on = {})
635+ )
636+ old_snapshot_b = make_snapshot (
637+ SqlModel (name = "b" , query = parse_one ("select 1, ds FROM a" ), depends_on = {"a" })
638+ )
639+ snapshot_a = make_snapshot (SqlModel (name = "a" , query = parse_one ("select 2, ds" ), depends_on = {}))
640+ snapshot_b = make_snapshot (
641+ SqlModel (name = "b" , query = parse_one ("select 1, ds FROM a" ), depends_on = {"a" })
642+ )
643+ snapshot_b .categorize_as (SnapshotChangeCategory .FORWARD_ONLY )
644+ snapshot_b .add_interval ("2022-01-01" , now ())
645+
646+ context_diff_mock = mocker .Mock ()
647+ context_diff_mock .snapshots = {"a" : snapshot_a , "b" : snapshot_b }
648+ context_diff_mock .added = set ()
649+ context_diff_mock .removed = set ()
650+ context_diff_mock .directly_modified .side_effect = lambda x : x == "a"
651+ context_diff_mock .modified_snapshots = {
652+ "a" : (snapshot_a , old_snapshot_a ),
653+ "b" : (snapshot_b , old_snapshot_b ),
654+ }
655+ context_diff_mock .new_snapshots = {snapshot_a .snapshot_id : snapshot_a }
656+ context_diff_mock .added_materialized_models = set ()
657+
658+ plan = Plan (context_diff_mock )
659+ plan .set_choice (snapshot_a , SnapshotChangeCategory .BREAKING )
660+ # Make sure it does not get assigned INDIRECT_BREAKING
661+ assert snapshot_b .change_category == SnapshotChangeCategory .FORWARD_ONLY
0 commit comments