Skip to content

Commit c33f13b

Browse files
authored
chore(commits): Remove update_commit dual write function (#102180)
We're no longer planning on using the dual written tables, so removing these functions
1 parent 01e1d86 commit c33f13b

File tree

4 files changed

+4
-91
lines changed

4 files changed

+4
-91
lines changed

src/sentry/integrations/utils/commit_context.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
from sentry.models.commit import Commit
2929
from sentry.models.commitauthor import CommitAuthor
3030
from sentry.models.organization import Organization
31-
from sentry.releases.commits import create_commit, update_commit
32-
from sentry.releases.models import Commit as NewCommit
31+
from sentry.releases.commits import create_commit
3332
from sentry.shared_integrations.exceptions import ApiError
3433
from sentry.utils import metrics
3534
from sentry.utils.committers import get_stacktrace_path_from_event_frame
@@ -140,9 +139,7 @@ def get_or_create_commit_from_blame(
140139
key=blame.commit.commitId,
141140
)
142141
if commit.message == "":
143-
new_commit = NewCommit.objects.get(id=commit.id)
144-
update_commit(commit, new_commit, message=blame.commit.commitMessage)
145-
142+
commit.update(message=blame.commit.commitMessage)
146143
return commit
147144
except Commit.DoesNotExist:
148145
logger.info(

src/sentry/models/releases/set_commits.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@
3434
from sentry.models.releaseheadcommit import ReleaseHeadCommit
3535
from sentry.models.repository import Repository
3636
from sentry.plugins.providers.repository import RepositoryProvider
37-
from sentry.releases.commits import (
38-
bulk_create_commit_file_changes,
39-
get_or_create_commit,
40-
update_commit,
41-
)
37+
from sentry.releases.commits import bulk_create_commit_file_changes, get_or_create_commit
4238

4339

4440
class _CommitDataKwargs(TypedDict, total=False):
@@ -138,7 +134,7 @@ def set_commit(idx, data, release):
138134
date_added=commit_data.get("date_added"), # type: ignore[arg-type]
139135
)
140136
if not created and any(getattr(commit, key) != value for key, value in commit_data.items()):
141-
update_commit(commit, new_commit, **commit_data)
137+
commit.update(**commit_data)
142138

143139
if author is None:
144140
author = commit.author

src/sentry/releases/commits.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,6 @@ def get_or_create_commit(
128128
return old_commit, new_commit, created
129129

130130

131-
def update_commit(old_commit: OldCommit, new_commit: Commit, **fields) -> None:
132-
"""Update a commit in both tables if dual write is enabled."""
133-
with atomic_transaction(
134-
using=(
135-
router.db_for_write(OldCommit),
136-
router.db_for_write(Commit),
137-
)
138-
):
139-
old_commit.update(**fields)
140-
new_commit.update(**fields)
141-
142-
143131
def bulk_create_commit_file_changes(
144132
file_changes: list[OldCommitFileChange],
145133
) -> tuple[list[OldCommitFileChange], list[CommitFileChange]]:

tests/sentry/releases/test_commits.py

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
create_commit,
1515
get_dual_write_start_date,
1616
get_or_create_commit,
17-
update_commit,
1817
)
1918
from sentry.releases.models import Commit, CommitFileChange
2019
from sentry.testutils.cases import TestCase
@@ -241,73 +240,6 @@ def test_get_or_create_commit_backfills_to_new_table(self):
241240
assert new_commit.author == self.author
242241

243242

244-
class UpdateCommitTest(TestCase):
245-
def setUp(self):
246-
super().setUp()
247-
self.repo = Repository.objects.create(
248-
name="test-repo",
249-
organization_id=self.organization.id,
250-
)
251-
self.author = CommitAuthor.objects.create(
252-
organization_id=self.organization.id,
253-
254-
name="Test Author",
255-
)
256-
257-
def test_update_commit_with_dual_write(self):
258-
"""Test updating a commit updates both tables when new_commit is provided"""
259-
old_commit = OldCommit.objects.create(
260-
organization_id=self.organization.id,
261-
repository_id=self.repo.id,
262-
key="abc123",
263-
message="Initial message",
264-
author=self.author,
265-
)
266-
new_commit = Commit.objects.create(
267-
id=old_commit.id,
268-
organization_id=self.organization.id,
269-
repository_id=self.repo.id,
270-
key="abc123",
271-
message="Initial message",
272-
author=self.author,
273-
date_added=old_commit.date_added,
274-
)
275-
update_commit(old_commit, new_commit, message="Updated message")
276-
old_commit.refresh_from_db()
277-
new_commit.refresh_from_db()
278-
assert old_commit.message == "Updated message"
279-
assert new_commit.message == "Updated message"
280-
281-
def test_update_commit_atomic_transaction(self):
282-
"""Test that updates are atomic when dual write is enabled"""
283-
old_commit = OldCommit.objects.create(
284-
organization_id=self.organization.id,
285-
repository_id=self.repo.id,
286-
key="ghi789",
287-
message="Initial message",
288-
author=self.author,
289-
)
290-
new_commit = Commit.objects.create(
291-
id=old_commit.id,
292-
organization_id=self.organization.id,
293-
repository_id=self.repo.id,
294-
key="ghi789",
295-
message="Initial message",
296-
author=self.author,
297-
date_added=old_commit.date_added,
298-
)
299-
with (
300-
patch.object(Commit, "update", side_effect=Exception("Update failed")),
301-
pytest.raises(Exception, match="Update failed"),
302-
):
303-
update_commit(old_commit, new_commit, message="Should fail")
304-
305-
old_commit.refresh_from_db()
306-
new_commit.refresh_from_db()
307-
assert old_commit.message == "Initial message"
308-
assert new_commit.message == "Initial message"
309-
310-
311243
class CreateCommitFileChangeDualWriteTest(TestCase):
312244
def setUp(self):
313245
super().setUp()

0 commit comments

Comments
 (0)