diff --git a/src/sentry/models/avatars/base.py b/src/sentry/models/avatars/base.py index 457dac300cbba6..a457ed1998bdb1 100644 --- a/src/sentry/models/avatars/base.py +++ b/src/sentry/models/avatars/base.py @@ -50,6 +50,9 @@ def save(self, *args, **kwargs): def get_file(self): file_id = getattr(self, self.file_write_fk(), None) + if file_id is None: + return None + file_class = self.file_class() try: return file_class.objects.get(pk=file_id) diff --git a/src/sentry/notifications/notificationcontroller.py b/src/sentry/notifications/notificationcontroller.py index f45fdaec2d5415..3257e14eee6706 100644 --- a/src/sentry/notifications/notificationcontroller.py +++ b/src/sentry/notifications/notificationcontroller.py @@ -72,12 +72,13 @@ def __init__( self.type = type self.provider = provider - org_mapping = OrganizationMapping.objects.filter(organization_id=organization_id).first() - org = ( - serialize_organization_mapping(org_mapping) - if organization_id and org_mapping is not None - else None - ) + if organization_id is not None: + org_mapping = OrganizationMapping.objects.filter( + organization_id=organization_id + ).first() + org = serialize_organization_mapping(org_mapping) if org_mapping is not None else None + else: + org = None if org and features.has("organizations:team-workflow-notifications", org): self.recipients: list[Recipient] = [] for recipient in recipients: @@ -289,14 +290,13 @@ def _get_layered_setting_providers( ) ) - org_mapping = OrganizationMapping.objects.filter( - organization_id=self.organization_id - ).first() - org = ( - serialize_organization_mapping(org_mapping) - if self.organization_id and org_mapping is not None - else None - ) + if self.organization_id is not None: + org_mapping = OrganizationMapping.objects.filter( + organization_id=self.organization_id + ).first() + org = serialize_organization_mapping(org_mapping) if org_mapping is not None else None + else: + org = None has_team_workflow = org and features.has("organizations:team-workflow-notifications", org) for recipient in self.recipients: diff --git a/src/sentry/replays/lib/storage.py b/src/sentry/replays/lib/storage.py index 36629de5e8d26a..3fbbe101fed3ca 100644 --- a/src/sentry/replays/lib/storage.py +++ b/src/sentry/replays/lib/storage.py @@ -99,14 +99,20 @@ def set(self, segment: RecordingSegmentStorageMeta, value: bytes) -> None: class FilestoreBlob(Blob): """Filestore service driver blob manager.""" + def _segment_file(self, segment: RecordingSegmentStorageMeta) -> File: + if segment.file: + return segment.file + elif segment.file_id is not None: + return File.objects.get(pk=segment.file_id) + else: + raise ValueError("expected either segment.file or segment.file_id") + def delete(self, segment: RecordingSegmentStorageMeta) -> None: - file = segment.file or File.objects.get(pk=segment.file_id) - file.delete() + self._segment_file(segment).delete() @metrics.wraps("replays.lib.storage.FilestoreBlob.get") def get(self, segment: RecordingSegmentStorageMeta) -> bytes: - file = segment.file or File.objects.get(pk=segment.file_id) - return file.getfile().read() + return self._segment_file(segment).getfile().read() @metrics.wraps("replays.lib.storage.FilestoreBlob.set") def set(self, segment: RecordingSegmentStorageMeta, value: bytes) -> None: