#13734·pydantic

Serializing `mock.call` objects raises an exception

Author: tsiwtCreated Aug 28, 2026Updated Sep 16, 2026
Labelsbug V2

Originally reported in https://github.com/pydantic/pydantic-core/issues/1866:

The following code triggers a TypeError.

python
from unittest.mock import call
from pydantic_core import to_jsonable_python

# TypeError: '_Call' object cannot be converted to 'SchemaSerializer'
to_jsonable_python(call(1, 2, 3), fallback=lambda call: call.args)

We usually try very hard to avoid raising errors from serialization, this is also on a type inference pathway. I think it'd be reasonable to just hit fallback if the __pydantic_serializer__ attribute is invalid (this is the root cause of the TypeError).