-
Notifications
You must be signed in to change notification settings - Fork 154
Open
Description
Description
WsClient.on_message_async crashes with AttributeError: 'str' object has no attribute 'get' when the WebSocket server sends a non-object JSON message (e.g. a string heartbeat).
Root Cause
The sync on_message method correctly handles raw string messages:
def on_message(self, ws, message):
if isinstance(message, str):
message = json.loads(message)
message_type = message.get("type")But the async on_message_async skips the type check after parsing:
async def on_message_async(self, ws, message):
message = json.loads(message)
message_type = message.get("type") # crashes if json.loads returns a strWhen the server sends a JSON string value (e.g. "heartbeat"), json.loads('"heartbeat"') returns "heartbeat" (a str), and str has no .get() method.
Impact
This causes run_async() to raise an unhandled AttributeError, disconnecting the WebSocket client. In a reconnect loop, this results in a permanent crash cycle with no useful work being done.
Suggested Fix
Add an isinstance check after json.loads, matching the pattern in on_message:
async def on_message_async(self, ws, message):
if isinstance(message, str):
message = json.loads(message)
if not isinstance(message, dict):
return
message_type = message.get("type")
...Environment
- lighter-sdk 1.0.3
- Python 3.12
- websockets (legacy async client)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels