Skip to content

Commit 1df104b

Browse files
committed
Address hash problem
1 parent 2dda0cd commit 1df104b

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/sentry/tasks/commits.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from sentry.users.services.user.service import user_service
3434
from sentry.utils.cache import cache
3535
from sentry.utils.email import MessageBuilder
36-
from sentry.utils.hashlib import md5_text
36+
from sentry.utils.hashlib import hash_values
3737
from sentry.utils.http import absolute_uri
3838

3939
logger = logging.getLogger(__name__)
@@ -94,9 +94,10 @@ def get_github_compare_commits_cache_key(
9494
start_sha: str | None,
9595
end_sha: str,
9696
) -> str:
97-
digest = md5_text(
98-
organization_id, repository_id, provider or "", start_sha or "", end_sha
99-
).hexdigest()
97+
digest = hash_values(
98+
[organization_id, repository_id, provider or "", start_sha or "", end_sha],
99+
seed="fetch-commits:compare-commits",
100+
)
100101
return f"fetch-commits:compare-commits:v1:{digest}"
101102

102103

tests/sentry/tasks/test_commits.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
from sentry.models.releaseheadcommit import ReleaseHeadCommit
1414
from sentry.models.repository import Repository
1515
from sentry.silo.base import SiloMode
16-
from sentry.tasks.commits import fetch_commits, handle_invalid_identity
16+
from sentry.tasks.commits import (
17+
fetch_commits,
18+
get_github_compare_commits_cache_key,
19+
handle_invalid_identity,
20+
)
1721
from sentry.testutils.asserts import assert_slo_metric
1822
from sentry.testutils.cases import TestCase
1923
from sentry.testutils.silo import assume_test_silo_mode, control_silo_test
@@ -30,6 +34,14 @@ def _github_compare_commits_result(self, repo_name: str, end_sha: str) -> list[d
3034
{"id": end_sha, "repository": repo_name},
3135
]
3236

37+
def test_github_compare_commits_cache_key_avoids_ambiguous_id_collisions(
38+
self, mock_record: MagicMock
39+
) -> None:
40+
key_one = get_github_compare_commits_cache_key(1, 23, "integrations:github", "a", "b")
41+
key_two = get_github_compare_commits_cache_key(12, 3, "integrations:github", "a", "b")
42+
43+
assert key_one != key_two
44+
3345
def _test_simple_action(self, user, org):
3446
repo = Repository.objects.create(name="example", provider="dummy", organization_id=org.id)
3547
release = Release.objects.create(organization_id=org.id, version="abcabcabc")

0 commit comments

Comments
 (0)