From 13f6c374bf820726c610e27d5b7bf1e2a6dc6310 Mon Sep 17 00:00:00 2001 From: Peter Holloway Date: Tue, 31 Mar 2026 14:11:19 +0100 Subject: [PATCH] Serialize plan results to JSON compatible types earlier When a plan returns a value that is serializable but contains a nested value that is not (eg a list of an unserializable type), the check for whether it could be serialized was too lenient and the unserializable type would be stored only to fail later when it was sent to the message bus. Converting the result to a json compatible type (using mode='json') earlier allows any issues with nested fields to be caught and handled appropriately. --- src/blueapi/worker/event.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/blueapi/worker/event.py b/src/blueapi/worker/event.py index 367464457e..df9b54bb45 100644 --- a/src/blueapi/worker/event.py +++ b/src/blueapi/worker/event.py @@ -4,6 +4,7 @@ from bluesky.run_engine import RunEngineStateMachine from pydantic import Field, PydanticSchemaGenerationError, TypeAdapter +from pydantic_core import PydanticSerializationError from super_state_machine.extras import PropertyMachine, ProxyString from blueapi.utils import BlueapiBaseModel @@ -73,8 +74,8 @@ class TaskResult(BlueapiBaseModel): def from_result(cls, result: Any) -> Self: type_str = type(result).__name__ try: - value = TypeAdapter(type(result)).dump_python(result) - except PydanticSchemaGenerationError: + value = TypeAdapter(type(result)).dump_python(result, mode="json") + except (PydanticSchemaGenerationError, PydanticSerializationError): value = None return cls(result=value, type=type_str)