Skip to content

Commit 4bc2ada

Browse files
ref: make create or update typesafe (#75149)
<!-- Describe your PR here. -->
1 parent f222b77 commit 4bc2ada

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/sentry/models/release.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import re
66
from collections.abc import Mapping, Sequence
77
from time import time
8-
from typing import ClassVar
8+
from typing import ClassVar, TypedDict
99

1010
import orjson
1111
import sentry_sdk
@@ -36,6 +36,7 @@
3636
from sentry.locks import locks
3737
from sentry.models.activity import Activity
3838
from sentry.models.artifactbundle import ArtifactBundle
39+
from sentry.models.commitauthor import CommitAuthor
3940
from sentry.models.commitfilechange import CommitFileChange
4041
from sentry.models.grouphistory import GroupHistoryStatus, record_group_history
4142
from sentry.models.groupinbox import GroupInbox, GroupInboxRemoveAction, remove_group_from_inbox
@@ -178,6 +179,12 @@ def get_group_release_version(
178179
return release_version or None
179180

180181

182+
class _CommitDataKwargs(TypedDict, total=False):
183+
author: CommitAuthor
184+
message: str
185+
date_added: str
186+
187+
181188
@region_silo_model
182189
class Release(Model):
183190
"""
@@ -658,7 +665,6 @@ def set_commits(self, commit_list):
658665

659666
# TODO(dcramer): this function could use some cleanup/refactoring as it's a bit unwieldy
660667
from sentry.models.commit import Commit
661-
from sentry.models.commitauthor import CommitAuthor
662668
from sentry.models.group import Group, GroupStatus
663669
from sentry.models.grouplink import GroupLink
664670
from sentry.models.groupresolution import GroupResolution
@@ -752,7 +758,7 @@ def set_commits(self, commit_list):
752758
else:
753759
author = authors[author_email]
754760

755-
commit_data = {}
761+
commit_data: _CommitDataKwargs = {}
756762

757763
# Update/set message and author if they are provided.
758764
if author is not None:
@@ -768,14 +774,10 @@ def set_commits(self, commit_list):
768774
key=data["id"],
769775
defaults=commit_data,
770776
)
771-
if not created:
772-
commit_data = {
773-
key: value
774-
for key, value in commit_data.items()
775-
if getattr(commit, key) != value
776-
}
777-
if commit_data:
778-
commit.update(**commit_data)
777+
if not created and any(
778+
getattr(commit, key) != value for key, value in commit_data.items()
779+
):
780+
commit.update(**commit_data)
779781

780782
if author is None:
781783
author = commit.author

0 commit comments

Comments
 (0)