Skip to content

Commit 939b727

Browse files
committed
Fix: convert time field to float when broadcasting message
Problem: `broadcast_and_process_message` fails when the `message_dict` argument is set to None because the `time` field is then specified as a datetime object instead of a float. Solution: add a formatting function that converts the `time` key to a float.
1 parent 0fe41f6 commit 939b727

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/aleph/web/controllers/utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,12 @@ def broadcast_status_to_http_status(broadcast_status: BroadcastStatus) -> int:
310310
return message_status_to_http_status(message_status)
311311

312312

313+
def format_pending_message_dict(pending_message: BasePendingMessage) -> Dict[str, Any]:
314+
pending_message_dict = pending_message.dict(exclude_none=True)
315+
pending_message_dict["time"] = pending_message_dict["time"].timestamp()
316+
return pending_message_dict
317+
318+
313319
@shielded
314320
async def broadcast_and_process_message(
315321
pending_message: BasePendingMessage,
@@ -328,7 +334,7 @@ async def broadcast_and_process_message(
328334
:param request: The web request object, used to extract global state.
329335
:param logger: Logger.
330336
:param message_dict: The message as a dictionary, if already available. Used for optimization purposes;
331-
if not provided, the function will call pending_message.dict().
337+
if not provided, the function will call format_pending_message_dict().
332338
"""
333339

334340
# In sync mode, wait for a message processing event. We need to create the queue
@@ -358,7 +364,7 @@ async def broadcast_and_process_message(
358364
p2p_client = get_p2p_client_from_request(request)
359365

360366
message_topic = config.aleph.queue_topic.value
361-
message_dict = message_dict or pending_message.dict(exclude_none=True)
367+
message_dict = message_dict or format_pending_message_dict(pending_message)
362368

363369
failed_publications = await pub_on_p2p_topics(
364370
p2p_client=p2p_client,

0 commit comments

Comments
 (0)