@@ -90,26 +90,27 @@ def test_forward_only_dev(make_snapshot, mocker: MockerFixture):
9090 now_ds_mock .call_count == 2
9191
9292
93- def test_forward_only_plan_new_models_not_allowed (make_snapshot , mocker : MockerFixture ):
94- snapshot_a = make_snapshot (SqlModel (name = "a" , query = parse_one ("select 1, ds" )))
95- snapshot_a .categorize_as (SnapshotChangeCategory .BREAKING )
93+ def test_forward_only_plan_added_models (make_snapshot , mocker : MockerFixture ):
94+ snapshot_a = make_snapshot (SqlModel (name = "a" , query = parse_one ("select 1 as a, ds" )))
95+
96+ snapshot_b = make_snapshot (
97+ SqlModel (name = "b" , query = parse_one ("select a, ds from a" )), nodes = {"a" : snapshot_a .node }
98+ )
9699
97100 context_diff_mock = mocker .Mock ()
98- context_diff_mock .snapshots = {"a" : snapshot_a }
99- context_diff_mock .added = {"a " }
101+ context_diff_mock .snapshots = {"a" : snapshot_a , "b" : snapshot_b }
102+ context_diff_mock .added = {"b " }
100103 context_diff_mock .removed = set ()
101- context_diff_mock .modified_snapshots = {}
102- context_diff_mock .new_snapshots = {}
103- context_diff_mock .added_materialized_models = {"a" }
104-
105- with pytest .raises (
106- PlanError ,
107- match = "New models that require materialization can't be added as part of the forward-only plan." ,
108- ):
109- Plan (context_diff_mock , forward_only = True )
104+ context_diff_mock .modified_snapshots = {"a" : (snapshot_a , snapshot_a )}
105+ context_diff_mock .new_snapshots = {
106+ snapshot_a .snapshot_id : snapshot_a ,
107+ snapshot_b .snapshot_id : snapshot_b ,
108+ }
109+ context_diff_mock .added_materialized_models = {"b" }
110110
111- context_diff_mock .added_materialized_models = set ()
112111 Plan (context_diff_mock , forward_only = True )
112+ assert snapshot_a .change_category == SnapshotChangeCategory .FORWARD_ONLY
113+ assert snapshot_b .change_category == SnapshotChangeCategory .FORWARD_ONLY
113114
114115
115116def test_paused_forward_only_parent (make_snapshot , mocker : MockerFixture ):
@@ -577,6 +578,7 @@ def test_forward_only_models(make_snapshot, mocker: MockerFixture):
577578 kind = IncrementalByTimeRangeKind (time_column = "ds" , forward_only = True ),
578579 )
579580 )
581+ updated_snapshot .previous_versions = snapshot .all_versions
580582
581583 context_diff_mock = mocker .Mock ()
582584 context_diff_mock .snapshots = {"a" : updated_snapshot }
@@ -607,6 +609,7 @@ def test_indirectly_modified_forward_only_model(make_snapshot, mocker: MockerFix
607609 snapshot_a = make_snapshot (SqlModel (name = "a" , query = parse_one ("select 1 as a, ds" )))
608610 snapshot_a .categorize_as (SnapshotChangeCategory .BREAKING )
609611 updated_snapshot_a = make_snapshot (SqlModel (name = "a" , query = parse_one ("select 2 as a, ds" )))
612+ updated_snapshot_a .previous_versions = snapshot_a .all_versions
610613
611614 snapshot_b = make_snapshot (
612615 SqlModel (
@@ -618,12 +621,14 @@ def test_indirectly_modified_forward_only_model(make_snapshot, mocker: MockerFix
618621 )
619622 snapshot_b .categorize_as (SnapshotChangeCategory .FORWARD_ONLY )
620623 updated_snapshot_b = make_snapshot (snapshot_b .model , nodes = {"a" : updated_snapshot_a .model })
624+ updated_snapshot_b .previous_versions = snapshot_b .all_versions
621625
622626 snapshot_c = make_snapshot (
623627 SqlModel (name = "c" , query = parse_one ("select a, ds from b" )), nodes = {"b" : snapshot_b .model }
624628 )
625629 snapshot_c .categorize_as (SnapshotChangeCategory .BREAKING )
626630 updated_snapshot_c = make_snapshot (snapshot_c .model , nodes = {"b" : updated_snapshot_b .model })
631+ updated_snapshot_c .previous_versions = snapshot_c .all_versions
627632
628633 context_diff_mock = mocker .Mock ()
629634 context_diff_mock .snapshots = {
@@ -660,6 +665,65 @@ def test_indirectly_modified_forward_only_model(make_snapshot, mocker: MockerFix
660665 assert updated_snapshot_c .change_category == SnapshotChangeCategory .FORWARD_ONLY
661666
662667
668+ def test_added_model_with_forward_only_parent (make_snapshot , mocker : MockerFixture ):
669+ snapshot_a = make_snapshot (SqlModel (name = "a" , query = parse_one ("select 1 as a, ds" )))
670+ snapshot_a .categorize_as (SnapshotChangeCategory .FORWARD_ONLY )
671+
672+ snapshot_b = make_snapshot (SqlModel (name = "b" , query = parse_one ("select a, ds from a" )))
673+
674+ context_diff_mock = mocker .Mock ()
675+ context_diff_mock .snapshots = {
676+ "a" : snapshot_a ,
677+ "b" : snapshot_b ,
678+ }
679+ context_diff_mock .removed = set ()
680+ context_diff_mock .added = {"b" }
681+ context_diff_mock .added_materialized_models = set ()
682+ context_diff_mock .modified_snapshots = {}
683+ context_diff_mock .new_snapshots = {
684+ snapshot_b .snapshot_id : snapshot_b ,
685+ }
686+ context_diff_mock .has_snapshot_changes = True
687+ context_diff_mock .environment = "test_dev"
688+ context_diff_mock .previous_plan_id = "previous_plan_id"
689+
690+ Plan (context_diff_mock )
691+ assert snapshot_b .change_category == SnapshotChangeCategory .FORWARD_ONLY
692+
693+
694+ def test_added_forward_only_model (make_snapshot , mocker : MockerFixture ):
695+ snapshot_a = make_snapshot (
696+ SqlModel (
697+ name = "a" ,
698+ query = parse_one ("select 1 as a, ds" ),
699+ kind = IncrementalByTimeRangeKind (time_column = "ds" , forward_only = True ),
700+ )
701+ )
702+
703+ snapshot_b = make_snapshot (SqlModel (name = "b" , query = parse_one ("select a, ds from a" )))
704+
705+ context_diff_mock = mocker .Mock ()
706+ context_diff_mock .snapshots = {
707+ "a" : snapshot_a ,
708+ "b" : snapshot_b ,
709+ }
710+ context_diff_mock .removed = set ()
711+ context_diff_mock .added = {"a" , "b" }
712+ context_diff_mock .added_materialized_models = set ()
713+ context_diff_mock .modified_snapshots = {}
714+ context_diff_mock .new_snapshots = {
715+ snapshot_a .snapshot_id : snapshot_a ,
716+ snapshot_b .snapshot_id : snapshot_b ,
717+ }
718+ context_diff_mock .has_snapshot_changes = True
719+ context_diff_mock .environment = "test_dev"
720+ context_diff_mock .previous_plan_id = "previous_plan_id"
721+
722+ Plan (context_diff_mock )
723+ assert snapshot_a .change_category == SnapshotChangeCategory .BREAKING
724+ assert snapshot_b .change_category == SnapshotChangeCategory .BREAKING
725+
726+
663727def test_disable_restatement (make_snapshot , mocker : MockerFixture ):
664728 snapshot = make_snapshot (
665729 SqlModel (
0 commit comments