From 6703e65c55b8012fe2ee8f1aa1b6e02dfa78aacf Mon Sep 17 00:00:00 2001 From: anthony sottile <103459774+asottile-sentry@users.noreply.github.com> Date: Tue, 18 Jun 2024 13:58:20 -0400 Subject: [PATCH] ref: remove dead code in models.eventattachment (#72799) this fixes type checking in this module when BaseManager becomes checked --- src/sentry/models/eventattachment.py | 36 ++++++++-------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/src/sentry/models/eventattachment.py b/src/sentry/models/eventattachment.py index 678c187245a5da..ce7af44af26834 100644 --- a/src/sentry/models/eventattachment.py +++ b/src/sentry/models/eventattachment.py @@ -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 @@ -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 @@ -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 )