Open DMRobertson opened 2 years ago
Ahh, there is a model config option error_msg_templates
which might be useful here. And we could set this globally by defining our own BaseModel
, see https://pydantic-docs.helpmanual.io/usage/model_config/#change-behaviour-globally
Edit: I ended up creating RequestBodyModel
Rich notes:
I don't love the multiline error messages, particularly in the logs (where it is useful to be able to
grep ERROR
and hope to see most of the useful text). It might be better just to complain about the first error rather than trying to list all of them (which is what the jsonschema-based validation for config settings does).We can iterate on this in future though.
If anyone wants to see the kind of error messages Pydantic produces, try running this test case on my other pydantic experiment branch.
I think the name of the model isn't user-relevant. The "error context" (stuff in brackets) also loks like noise to an end-user. But we should be able to inspect the
ValidationError
and format it as we please.Originally posted by @DMRobertson in https://github.com/matrix-org/synapse/issues/13188#issuecomment-1175382843