Skip to content

Commit

Permalink
fix: incorrect MessageResult type on forgotton message flow
Browse files Browse the repository at this point in the history
  • Loading branch information
amalcaraz committed Jan 29, 2025
1 parent 76bbdf8 commit f521298
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion deployment/docker-build/dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ COPY deployment/migrations ./deployment/migrations
COPY deployment/scripts ./deployment/scripts
COPY .git ./.git
COPY src ./src
RUN pip install -e .

RUN pip install -e .[linting]
RUN pip install hatch

FROM base
Expand Down
10 changes: 7 additions & 3 deletions src/aleph/handlers/message_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@
from aleph.toolkit.timestamp import timestamp_to_datetime
from aleph.types.db_session import DbSession, DbSessionFactory
from aleph.types.files import FileType
from aleph.types.message_processing_result import ProcessedMessage
from aleph.types.message_processing_result import ProcessedMessage, RejectedMessage
from aleph.types.message_status import (
ErrorCode,
InvalidMessageException,
InvalidMessageFormat,
InvalidSignature,
Expand Down Expand Up @@ -378,7 +379,7 @@ async def verify_and_fetch(

async def process(
self, session: DbSession, pending_message: PendingMessageDb
) -> ProcessedMessage:
) -> ProcessedMessage | RejectedMessage:
"""
Process a pending message.
Expand Down Expand Up @@ -415,7 +416,10 @@ async def process(
forgotten_message=forgotten_message,
pending_message=pending_message,
)
return ProcessedMessage(message=forgotten_message, is_confirmation=True)
return RejectedMessage(
pending_message=pending_message,
error_code=ErrorCode.FORGET_TARGET_NOT_FOUND,
)

message = await self.verify_and_fetch(
session=session, pending_message=pending_message
Expand Down
9 changes: 6 additions & 3 deletions tests/message_processing/test_process_forgotten_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from aleph.handlers.message_handler import MessageHandler
from aleph.storage import StorageService
from aleph.types.db_session import DbSessionFactory
from aleph.types.message_processing_result import ProcessedMessage, RejectedMessage
from aleph.types.message_status import ErrorCode

from .load_fixtures import load_fixture_message_list

Expand Down Expand Up @@ -47,7 +49,7 @@ async def test_duplicated_forgotten_message(
session=session,
pending_message=m1,
)
assert test1
assert isinstance(test1, ProcessedMessage)

res1 = cast(
MessageDb,
Expand All @@ -60,7 +62,7 @@ async def test_duplicated_forgotten_message(
session=session,
pending_message=m2,
)
assert test2
assert isinstance(test2, ProcessedMessage)

res2 = cast(
MessageDb,
Expand All @@ -73,7 +75,8 @@ async def test_duplicated_forgotten_message(
session=session,
pending_message=m3,
)
assert test3
assert isinstance(test3, RejectedMessage)
assert test3.error_code == ErrorCode.FORGET_TARGET_NOT_FOUND

res3 = cast(
MessageDb,
Expand Down

0 comments on commit f521298

Please sign in to comment.