fix: serialize callbacks to string only in JSON mode to preserve closures during copy

This commit is contained in:
Greyson LaLonde
2026-03-19 20:13:54 -04:00
parent d983eca2dd
commit 756e939543

View File

@@ -91,6 +91,6 @@ def callable_to_string(fn: Callable[..., Any]) -> str:
SerializableCallable = Annotated[
Callable[..., Any],
BeforeValidator(string_to_callable),
PlainSerializer(callable_to_string, return_type=str),
PlainSerializer(callable_to_string, return_type=str, when_used="json"),
WithJsonSchema({"type": "string"}),
]