Skip to content

Commit 151135e

Browse files
authored
Fix: determine SnapshotTableInfo equality with fingerprint only (#3980)
1 parent 8c793ab commit 151135e

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

sqlmesh/core/snapshot/definition.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,12 @@ class SnapshotTableInfo(PydanticModel, SnapshotInfoMixin, frozen=True):
481481
def __lt__(self, other: SnapshotTableInfo) -> bool:
482482
return self.name < other.name
483483

484+
def __eq__(self, other: t.Any) -> bool:
485+
return isinstance(other, SnapshotTableInfo) and self.fingerprint == other.fingerprint
486+
487+
def __hash__(self) -> int:
488+
return hash((self.__class__, self.name, self.fingerprint))
489+
484490
def table_name(self, is_deployable: bool = True) -> str:
485491
"""Full table name pointing to the materialized location of the snapshot.
486492

tests/core/test_snapshot.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,48 @@ def test_fingerprint_virtual_properties(model: Model, parent_model: Model):
10351035
assert updated_fingerprint.data_hash == fingerprint.data_hash
10361036

10371037

1038+
def test_tableinfo_equality():
1039+
snapshot_a = SnapshotTableInfo(
1040+
name="test_schema.a",
1041+
fingerprint=SnapshotFingerprint(data_hash="1", metadata_hash="1"),
1042+
version="test_version",
1043+
physical_schema="test_physical_schema",
1044+
parents=[],
1045+
dev_table_suffix="dev",
1046+
)
1047+
1048+
snapshot_b = SnapshotTableInfo(
1049+
name="test_schema.b",
1050+
fingerprint=SnapshotFingerprint(data_hash="1", metadata_hash="1"),
1051+
version="test_version",
1052+
physical_schema="test_physical_schema",
1053+
parents=[],
1054+
dev_table_suffix="dev",
1055+
)
1056+
1057+
snapshot_c = SnapshotTableInfo(
1058+
name="test_schema.c",
1059+
fingerprint=SnapshotFingerprint(data_hash="1", metadata_hash="1"),
1060+
version="test_version",
1061+
physical_schema="test_physical_schema",
1062+
parents=[snapshot_a.snapshot_id, snapshot_b.snapshot_id],
1063+
dev_table_suffix="dev",
1064+
)
1065+
1066+
# parents in different order than snapshot_c
1067+
snapshot_c2 = SnapshotTableInfo(
1068+
name="test_schema.c",
1069+
fingerprint=SnapshotFingerprint(data_hash="1", metadata_hash="1"),
1070+
version="test_version",
1071+
physical_schema="test_physical_schema",
1072+
parents=[snapshot_b.snapshot_id, snapshot_a.snapshot_id],
1073+
dev_table_suffix="dev",
1074+
)
1075+
1076+
assert snapshot_c is not snapshot_c2
1077+
assert snapshot_c == snapshot_c2
1078+
1079+
10381080
def test_stamp(model: Model):
10391081
original_fingerprint = fingerprint_from_node(model, nodes={})
10401082

0 commit comments

Comments
 (0)