Skip to content

Commit 1f01f62

Browse files
fix(preprod): Skip images with missing hashes in fingerprint instead of using empty strings
1 parent 064e0da commit 1f01f62

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

src/sentry/preprod/snapshots/tasks.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,13 @@ def _build_comparison_fingerprints(manifest: ComparisonManifest) -> set[tuple[st
119119
if image.status == "unchanged":
120120
continue
121121
if image.status in ("changed", "added"):
122-
fingerprints.add((name, image.status, image.head_hash or ""))
122+
if not image.head_hash:
123+
continue
124+
fingerprints.add((name, image.status, image.head_hash))
123125
elif image.status == "renamed":
124-
fingerprints.add(
125-
(name, "renamed", image.head_hash or "", image.previous_image_file_name or "")
126-
)
126+
if not image.head_hash or not image.previous_image_file_name:
127+
continue
128+
fingerprints.add((name, "renamed", image.head_hash, image.previous_image_file_name))
127129
else:
128130
fingerprints.add((name, image.status))
129131
return fingerprints

tests/sentry/preprod/snapshots/test_auto_approve.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,33 @@ def test_empty_manifest_returns_empty_set(self):
136136
fps = _build_comparison_fingerprints(manifest)
137137
assert fps == set()
138138

139+
def test_skips_changed_with_missing_head_hash(self):
140+
manifest = self._make_manifest(
141+
{
142+
"no_hash.png": ComparisonImageResult(status="changed", base_hash="abc"),
143+
"has_hash.png": ComparisonImageResult(
144+
status="changed", head_hash="def", base_hash="ghi"
145+
),
146+
}
147+
)
148+
fps = _build_comparison_fingerprints(manifest)
149+
assert fps == {("has_hash.png", "changed", "def")}
150+
151+
def test_skips_renamed_with_missing_hash_or_previous_name(self):
152+
manifest = self._make_manifest(
153+
{
154+
"no_hash.png": ComparisonImageResult(
155+
status="renamed", previous_image_file_name="old.png"
156+
),
157+
"no_prev.png": ComparisonImageResult(status="renamed", head_hash="abc"),
158+
"valid.png": ComparisonImageResult(
159+
status="renamed", head_hash="def", previous_image_file_name="old_valid.png"
160+
),
161+
}
162+
)
163+
fps = _build_comparison_fingerprints(manifest)
164+
assert fps == {("valid.png", "renamed", "def", "old_valid.png")}
165+
139166

140167
def _mock_session_with_manifests(manifests_by_key: dict[str, bytes]) -> MagicMock:
141168
session = MagicMock()

0 commit comments

Comments
 (0)