Skip to content

Commit 90fd8d2

Browse files
committed
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.
1 parent 56e5b2c commit 90fd8d2

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/blueapi/worker/event.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from bluesky.run_engine import RunEngineStateMachine
66
from pydantic import Field, PydanticSchemaGenerationError, TypeAdapter
7+
from pydantic_core import PydanticSerializationError
78
from super_state_machine.extras import PropertyMachine, ProxyString
89

910
from blueapi.utils import BlueapiBaseModel
@@ -73,8 +74,8 @@ class TaskResult(BlueapiBaseModel):
7374
def from_result(cls, result: Any) -> Self:
7475
type_str = type(result).__name__
7576
try:
76-
value = TypeAdapter(type(result)).dump_python(result)
77-
except PydanticSchemaGenerationError:
77+
value = TypeAdapter(type(result)).dump_python(result, mode="json")
78+
except (PydanticSchemaGenerationError, PydanticSerializationError):
7879
value = None
7980
return cls(result=value, type=type_str)
8081

0 commit comments

Comments
 (0)