@@ -657,6 +657,58 @@ def test_select_models_with_external_parent(mocker: MockerFixture):
657657 assert expanded_selections == {added_model .fqn }
658658
659659
660+ def test_select_models_local_tags_take_precedence_over_remote (
661+ mocker : MockerFixture , make_snapshot : t .Callable
662+ ) -> None :
663+ existing_model = SqlModel (
664+ name = "db.existing" ,
665+ query = d .parse_one ("SELECT 1 AS a" ),
666+ )
667+ new_model = SqlModel (
668+ name = "db.new" ,
669+ tags = ["a" ],
670+ query = d .parse_one ("SELECT 1 as a" ),
671+ )
672+
673+ existing_snapshot = make_snapshot (existing_model )
674+ existing_snapshot .categorize_as (SnapshotChangeCategory .BREAKING )
675+ new_snapshot = make_snapshot (new_model )
676+ new_snapshot .categorize_as (SnapshotChangeCategory .BREAKING )
677+
678+ env_name = "test_env"
679+
680+ state_reader_mock = mocker .Mock ()
681+ state_reader_mock .get_environment .return_value = Environment (
682+ name = env_name ,
683+ snapshots = [existing_snapshot .table_info ],
684+ start_at = "2023-01-01" ,
685+ end_at = "2023-02-01" ,
686+ plan_id = "test_plan_id" ,
687+ )
688+ state_reader_mock .get_snapshots .return_value = {
689+ existing_snapshot .snapshot_id : existing_snapshot
690+ }
691+
692+ local_models : UniqueKeyDict [str , Model ] = UniqueKeyDict ("models" )
693+ local_existing = existing_model .copy (update = {"tags" : ["a" ]}) # type: ignore
694+ local_models [local_existing .fqn ] = local_existing
695+ local_new = new_model .copy ()
696+ local_models [local_new .fqn ] = local_new
697+
698+ selector = Selector (state_reader_mock , local_models )
699+
700+ selected = selector .select_models (["tag:a" ], env_name )
701+
702+ # both should get selected because they both now have the 'a' tag locally, even though one exists in remote state without the 'a' tag
703+ _assert_models_equal (
704+ selected ,
705+ {
706+ local_existing .fqn : local_existing ,
707+ local_new .fqn : local_new ,
708+ },
709+ )
710+
711+
660712def _assert_models_equal (actual : t .Dict [str , Model ], expected : t .Dict [str , Model ]) -> None :
661713 assert set (actual ) == set (expected )
662714 for name , model in actual .items ():
0 commit comments