Skip to content

Commit 049a5d2

Browse files
wip: cannot lookup by None pkey
1 parent fac79ed commit 049a5d2

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

src/sentry/models/avatars/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ def save(self, *args, **kwargs):
5050

5151
def get_file(self):
5252
file_id = getattr(self, self.file_write_fk(), None)
53+
if file_id is None:
54+
return None
55+
5356
file_class = self.file_class()
5457
try:
5558
return file_class.objects.get(pk=file_id)

src/sentry/notifications/notificationcontroller.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,13 @@ def __init__(
7272
self.type = type
7373
self.provider = provider
7474

75-
org_mapping = OrganizationMapping.objects.filter(organization_id=organization_id).first()
76-
org = (
77-
serialize_organization_mapping(org_mapping)
78-
if organization_id and org_mapping is not None
79-
else None
80-
)
75+
if organization_id is not None:
76+
org_mapping = OrganizationMapping.objects.filter(
77+
organization_id=organization_id
78+
).first()
79+
org = serialize_organization_mapping(org_mapping) if org_mapping is not None else None
80+
else:
81+
org = None
8182
if org and features.has("organizations:team-workflow-notifications", org):
8283
self.recipients: list[Recipient] = []
8384
for recipient in recipients:
@@ -289,14 +290,13 @@ def _get_layered_setting_providers(
289290
)
290291
)
291292

292-
org_mapping = OrganizationMapping.objects.filter(
293-
organization_id=self.organization_id
294-
).first()
295-
org = (
296-
serialize_organization_mapping(org_mapping)
297-
if self.organization_id and org_mapping is not None
298-
else None
299-
)
293+
if self.organization_id is not None:
294+
org_mapping = OrganizationMapping.objects.filter(
295+
organization_id=self.organization_id
296+
).first()
297+
org = serialize_organization_mapping(org_mapping) if org_mapping is not None else None
298+
else:
299+
org = None
300300
has_team_workflow = org and features.has("organizations:team-workflow-notifications", org)
301301

302302
for recipient in self.recipients:

src/sentry/replays/lib/storage.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,20 @@ def set(self, segment: RecordingSegmentStorageMeta, value: bytes) -> None:
9999
class FilestoreBlob(Blob):
100100
"""Filestore service driver blob manager."""
101101

102+
def _segment_file(self, segment: RecordingSegmentStorageMeta) -> File:
103+
if segment.file:
104+
return segment.file
105+
elif segment.file_id is not None:
106+
return File.objects.get(pk=segment.file_id)
107+
else:
108+
raise ValueError("expected either segment.file or segment.file_id")
109+
102110
def delete(self, segment: RecordingSegmentStorageMeta) -> None:
103-
file = segment.file or File.objects.get(pk=segment.file_id)
104-
file.delete()
111+
self._segment_file(segment).delete()
105112

106113
@metrics.wraps("replays.lib.storage.FilestoreBlob.get")
107114
def get(self, segment: RecordingSegmentStorageMeta) -> bytes:
108-
file = segment.file or File.objects.get(pk=segment.file_id)
109-
return file.getfile().read()
115+
return self._segment_file(segment).getfile().read()
110116

111117
@metrics.wraps("replays.lib.storage.FilestoreBlob.set")
112118
def set(self, segment: RecordingSegmentStorageMeta, value: bytes) -> None:

0 commit comments

Comments
 (0)