Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: fix lookups by None keys #75156

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/sentry/models/avatars/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 14 additions & 14 deletions src/sentry/notifications/notificationcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 10 additions & 4 deletions src/sentry/replays/lib/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading