PyMax icon indicating copy to clipboard operation
PyMax copied to clipboard

GetReactionsPayload serializes messageIds as strings, causing validation error and WebSocket disconnect

Open zephyr-m opened this issue 3 months ago • 3 comments

Environment

  • maxapi-python: 2.4.0
  • Python: 3.12
  • Client: WebClient

Problem

Calling get_reactions() sends messageIds as strings:

payload={'chatId': -72218689395283, 'messageIds': ['117093598374465578']}

MAX rejects the request:

proto.payload: Expected number at 30 (Ошибка валидации)

After this response, the WebSocket connection is closed. This can interrupt unrelated work such as chat synchronization.

Cause

GetReactionsPayload currently declares:

class GetReactionsPayload(CamelModel):
    chat_id: int
    message_ids: list[str]

Other message payloads and the MAX endpoint expect numeric message IDs.

Expected fix

Change the field to:

message_ids: list[int]

The service method annotation should be changed to list[int] as well.

I verified locally that coercing these IDs to integers produces the expected MessagePack number type

zephyr-m avatar Aug 14 '26 11:08 zephyr-m

Thanks, i will discover that issue

ink-developer avatar Aug 14 '26 15:08 ink-developer

I'm hitting the same str-vs-int message_id class of bugs on the TCP client (not WebSocket), with maxapi-python 2.4.0. Two more places besides GetReactionsPayload:

1. RemoveReactionPayload.message_id: str (opcode 179) — Message.unreact() calls remove_reaction(chat_id, message_id=str(self.id)), the payload serializes messageId as a string, and the server replies proto.payload: Expected number at 24 and closes the connection. Confirmed on a live account.

2. ReactionUpdateEvent.messageId: str (inbound, opcode 155) — the server sends messageId as an int; ReactionUpdateEvent.model_validate(frame.payload) raises Input should be a valid string, the dispatcher logs inbound event handler failed opcode=155 and drops the frame.

Fix suggestion: type message_id / messageId as int in RemoveReactionPayload and ReactionUpdateEvent (and AddReactionPayload while at it) — same as VotePollPayload.message_id: int which works fine. There's already a # Сокет просит int а вс str comment on ReadMessagesPayload.message_id, so the socket clearly wants ints on TCP.

Workaround until fixed: bypass the broken Pydantic models with raw app.invoke(Opcode.MSG_CANCEL_REACTION, {"chatId": int, "messageId": int}), and neutralise the inbound resolver for NOTIF_MSG_REACTIONS_CHANGED so the frame falls through to RAW and never reaches ReactionUpdateEvent.model_validate.

KostinPavel avatar Aug 18 '26 19:08 KostinPavel

Fixed in dev/2.4.1. The fix will be included in the next release.

ink-developer avatar Aug 21 '26 18:08 ink-developer