aleph-im / aleph-client

Lightweight Python Client library for the Aleph.im network

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for forgotten messages

hoh opened this issue · comments

This issue is between aleph-message and aleph-client.

Querying a message using get_message(item_hash) raises the exception MessageNotFoundError if the message has been forgotten. This is not clear to users since the message is found and does exist, but has been forgotten.

When using get_messages(hashes=[item_hash], ignore_invalid_messages=False), a mapping error appears from aleph-message, indicating that the item_content field cannot be parsed (obviously, since it has been deleted when forgetting the message).

Traceback (most recent call last):
  File "/app/extra/plugins/python/helpers/pydev/pydevconsole.py", line 364, in runcode
    coro = func()
  File "<input>", line 1, in <module>
  File "/home/sepal/Repos/Aleph.im/aleph-client/src/aleph_client/synchronous.py", line 55, in get_message
    return wrap_async(asynchronous.get_message)(
  File "/home/sepal/Repos/Aleph.im/aleph-client/src/aleph_client/synchronous.py", line 22, in func_caller
    return loop.run_until_complete(func(*args, **kwargs))
  File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/home/sepal/Repos/Aleph.im/aleph-client/src/aleph_client/asynchronous.py", line 658, in get_message
    messages_response = await get_messages(
  File "/home/sepal/Repos/Aleph.im/aleph-client/src/aleph_client/asynchronous.py", line 630, in get_messages
    raise e
  File "/home/sepal/Repos/Aleph.im/aleph-client/src/aleph_client/asynchronous.py", line 626, in get_messages
    message = Message(**message_raw)
  File "/opt/venv/aleph-client/lib/python3.10/site-packages/aleph_message/models/__init__.py", line 388, in Message
    return message_class(**message_dict)
  File "pydantic/main.py", line 339, in pydantic.main.BaseModel.__init__
  File "pydantic/main.py", line 1056, in pydantic.main.validate_model
  File "pydantic/fields.py", line 871, in pydantic.fields.ModelField.validate
  File "pydantic/fields.py", line 1121, in pydantic.fields.ModelField._apply_validators
  File "pydantic/class_validators.py", line 282, in pydantic.class_validators._generic_validator_cls.lambda4
  File "/opt/venv/aleph-client/lib/python3.10/site-packages/aleph_message/models/__init__.py", line 290, in check_item_hash
    item_content: str = values["item_content"]
KeyError: 'item_content'

We should have a way to make get_message(item_hash) either return an object of class ForgottenMessage, or raise an exception ForgottenMessageError to explicitly inform the user that the message requested has been forgotten.

The plan is to stop publishing forgotten messages in the messages endpoint, it just doesn't make sense.