aleph-im / aleph-message

Aleph.im message specification
MIT License
0 stars 5 forks source link

ValidationError when listening to messages on aleph-sdk-python 0.6.0 #51

Open MHHukiewitz opened 1 year ago

MHHukiewitz commented 1 year ago

The following error occurs when I start listening to Aleph messages with AlephClient.watch_messaages():

ValidationError(model='AggregateMessage', errors=[{'loc': ('_id',), 'msg': 'value is not a valid dict', 'type': 'type_error.dict'}])>
Traceback (most recent call last):
  File "/home/mik/PycharmProjects/yourtrading-ai/fishnet-cod/src/fishnet_cod/local_executor.py", line 50, in main
    await listen()
  File "/home/mik/PycharmProjects/yourtrading-ai/fishnet-cod/src/fishnet_cod/local_executor.py", line 37, in listen
    async for message in aars_client.session.watch_messages(
  File "/home/mik/PycharmProjects/yourtrading-ai/fishnet-cod/.venv/lib/python3.9/site-packages/aleph/sdk/client.py", line 812, in watch_messages
    yield Message(**data)
  File "/home/mik/PycharmProjects/yourtrading-ai/fishnet-cod/.venv/lib/python3.9/site-packages/aleph_message/models/__init__.py", line 333, in Message
    return message_class(**message_dict)
  File "pydantic/main.py", line 342, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for AggregateMessage
_id
  value is not a valid dict (type=type_error.dict)

It seems there are sometimes messages with _id or id_ fields when querying api2.aleph.im

odesenfans commented 1 year ago

The id_ field is a MongoDB ID and should never be shown, so that's a bug in the message API. I thought it was resolved. Anyway, it will never appear again with the new version so I wouldn't care too much about it.

The aggregate issue you mentioned is more problematic. Aggregates are supposed to be a key/value store. Some users post non-dict aggregates and these messages can be accepted on older pyaleph versions. I made the switch to enable this validation on the Postgres version, but it seems I was a bit trigger-happy with this change and I did not think about the messages currently stored on Mongo nodes. Here is the line that causes your problem in aleph-message.

We can revert it for now.