thumbnail: Remove type: ignore.

(An alternate solution is message_classes: list[type[Message |
ArchivedMessage]].)

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-10-04 10:24:32 -07:00 committed by Alex Vandiver
parent 912c1b5984
commit 1b4e02c5d0
1 changed files with 3 additions and 6 deletions

View File

@ -19,7 +19,7 @@ from zerver.lib.thumbnail import (
rewrite_thumbnailed_images,
)
from zerver.lib.upload import save_attachment_contents, upload_backend
from zerver.models import AbstractMessage, ArchivedMessage, ImageAttachment, Message
from zerver.models import ArchivedMessage, ImageAttachment, Message
from zerver.worker.base import QueueProcessingWorker, assign_queue
logger = logging.getLogger(__name__)
@ -158,12 +158,9 @@ def ensure_thumbnails(image_attachment: ImageAttachment) -> int:
def update_message_rendered_content(
realm_id: int, path_id: str, image_data: MarkdownImageMetadata | None
) -> None:
message_classes: list[type[AbstractMessage]] = [Message, ArchivedMessage]
for message_class in message_classes:
for message_class in (Message, ArchivedMessage):
messages_with_image = (
message_class._default_manager.filter( # type: ignore[misc] # Both Message and ArchivedMessage have an "attachment" many-to-many, but this is not guaranteed by the type system
realm_id=realm_id, attachment__path_id=path_id
)
message_class.objects.filter(realm_id=realm_id, attachment__path_id=path_id)
.select_for_update(of=("self",))
.order_by("id")
)