This is a Minimal reproducible example of a weird error from Pydantic, I got a bit turned around by today. Thanks to Robert Cox for rubber-ducking my hellish code (it wasn't this small)
Exception has occurred: PydanticSerializationError
Unable to serialize unknown type: <class 'pydantic.fields.FieldInfo'>
File "/Users/lewiscowles/Projects/study/pydantic-horror-show/pydantic_horror_show/__init__.py", line 13, in <module>
json = c.json(by_alias=True)
^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.PydanticSerializationError: Unable to serialize unknown type: <class 'pydantic.fields.FieldInfo'>
Well it's simple, just remove the comma, after field b is defined.
https://pylint.pycqa.org/en/latest/user_guide/messages/refactor/trailing-comma-tuple.html
Annoyingly I was using Ruff, black, mypy and some more linting in my project; they all missed this. My Google search also turned up nothing of much use.
So here is a repo with a minimal example and the advice on fixing 🙃
Pydantic is great. I'd consider this a weakness of implementation though. It's a bit of a footgun. Maybe the error could be nicer; and specifically call out two fields in a tuple being unable to de-serialize.
It's still a great tool, and I hope to avoid this footgun in future 😄.