Refuse failed attachments in messages through a zone port

The messaging zone asks a new AttachmentStates port whether any listed
attachment of the chat has failed and answers 409 conflict before the
message is stored; queued and processing attachments can still be
sent right after the upload. The check runs only on the first execution
of a key, so a replay returns the original 201 even if the attachment
failed later. main.py wires the port to the attachments directory, so
neither zone reads the other's tables.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Artyom
2026-10-29 01:09:31 +03:00
co-authored by Claude Opus 5.5
parent b152b6e07e
commit 34741dc2d2
8 changed files with 95 additions and 12 deletions
+16 -2
View File
@@ -6,7 +6,7 @@ from dishka import Provider, Scope, make_async_container, provide
from dishka.integrations.fastapi import FastapiProvider, setup_dishka
from fastapi import FastAPI
from messenger.attachments.application.ports import ChatMembership
from messenger.attachments.application.ports import AttachmentDirectory, ChatMembership
from messenger.attachments.config import AttachmentsSettings
from messenger.attachments.entrypoints.errors import ERROR_CODES as ATTACHMENT_ERRORS
from messenger.attachments.entrypoints.http import UPLOAD_PATH, attachments_router, uploads_router
@@ -23,7 +23,7 @@ from messenger.identity.entrypoints.http import sessions_router
from messenger.identity.entrypoints.ioc import IdentityProvider
from messenger.identity.entrypoints.journal import LOG_FIELDS as IDENTITY_FIELDS
from messenger.identity.entrypoints.journal import IdentityJournal
from messenger.messaging.application.ports import ChatDirectory
from messenger.messaging.application.ports import AttachmentStates, ChatDirectory
from messenger.messaging.config import MessagingSettings
from messenger.messaging.domain.events import ChatCreated, MessagePosted
from messenger.messaging.entrypoints.errors import ERROR_CODES as MESSAGING_ERRORS
@@ -58,11 +58,25 @@ class MessagingMembership:
return await self._chats.chat_for_member(chat_id, user_id) is not None
class AttachmentGate:
__slots__ = ("_attachments",)
def __init__(self, attachments: AttachmentDirectory) -> None:
self._attachments = attachments
async def unusable(self, chat_id: UUID, attachment_ids: Sequence[UUID]) -> bool:
return await self._attachments.failed_among(chat_id, attachment_ids)
class ZoneLinks(Provider):
@provide(scope=Scope.APP)
def membership(self, chats: ChatDirectory) -> ChatMembership:
return MessagingMembership(chats)
@provide(scope=Scope.APP)
def attachment_states(self, attachments: AttachmentDirectory) -> AttachmentStates:
return AttachmentGate(attachments)
def wire_events(bus: EventBus, logger: Logger) -> None:
identity = IdentityJournal(logger)