Skip to content

Commit

Permalink
ref: remove dead code in models.eventattachment (#72799)
Browse files Browse the repository at this point in the history
this fixes type checking in this module when BaseManager becomes checked

<!-- Describe your PR here. -->
  • Loading branch information
asottile-sentry authored Jun 18, 2024
1 parent 7bf1ba4 commit 6703e65
Showing 1 changed file with 10 additions and 26 deletions.
36 changes: 10 additions & 26 deletions src/sentry/models/eventattachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from typing import IO, Any

import zstandard
from django.conf import settings
from django.core.cache import cache
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
Expand Down Expand Up @@ -169,7 +168,7 @@ def getfile(self) -> IO[bytes]:

@classmethod
def putfile(cls, project_id: int, attachment: CachedAttachment) -> PutfileResult:
from sentry.models.files import File, FileBlob
from sentry.models.files import FileBlob

content_type = normalize_content_type(attachment.content_type, attachment.name)
data = attachment.data
Expand All @@ -179,34 +178,19 @@ def putfile(cls, project_id: int, attachment: CachedAttachment) -> PutfileResult

blob = BytesIO(data)

# NOTE: we still keep the old code around for a while before complete removing it
store_blobs = True
size, checksum = get_size_and_checksum(blob)

if store_blobs:
size, checksum = get_size_and_checksum(blob)

if can_store_inline(data) and in_random_rollout("eventattachments.store-small-inline"):
blob_path = ":" + data.decode()
else:
blob_path = "eventattachments/v1/" + FileBlob.generate_unique_path()

storage = get_storage()
compressed_blob = BytesIO(zstandard.compress(data))
storage.save(blob_path, compressed_blob)

return PutfileResult(
content_type=content_type, size=size, sha1=checksum, blob_path=blob_path
)
if can_store_inline(data) and in_random_rollout("eventattachments.store-small-inline"):
blob_path = ":" + data.decode()
else:
blob_path = "eventattachments/v1/" + FileBlob.generate_unique_path()

file = File.objects.create(
name=attachment.name,
type=attachment.type,
headers={"Content-Type": content_type},
)
file.putfile(blob, blob_size=settings.SENTRY_ATTACHMENT_BLOB_SIZE)
storage = get_storage()
compressed_blob = BytesIO(zstandard.compress(data))
storage.save(blob_path, compressed_blob)

return PutfileResult(
content_type=content_type, size=file.size, sha1=file.checksum, file_id=file.id
content_type=content_type, size=size, sha1=checksum, blob_path=blob_path
)


Expand Down

0 comments on commit 6703e65

Please sign in to comment.