pallets-eco / wtforms

A flexible forms validation and rendering library for Python.
https://wtforms.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.51k stars 395 forks source link

Form field errors not JSON serializable with default Flask JSONProvider #829

Closed jwag956 closed 1 week ago

jwag956 commented 9 months ago

The decision in 3.0 to use None as a dictionary key for holding form level errors #595 has the unfortunate side-effect of not allowing the JSON serializer to sort keys - which is the default set up by Flask.

One gets the error: TypeError: '<' not supported between instances of 'NoneType' and 'str'

Not sure of a good solution since it has been this way for a couple years now - a simple but not great solution would be to offer a configuration option to change the key.

I also realize that wtforms isn't explicitly tied to Flask - though as a low level library it would be nice if it didn't force the behavior of applications and higher level frameworks.

Environment

davidism commented 9 months ago

I don't mind just changing it to "" or "__form__" in a feature release.

jwag956 commented 8 months ago

Thanks - a comment in #595 suggests 'all' - same as django - I don't really care - though using anything that could be confused as core python I think would just cause confusion (also - it isn't all errors!). 'form' seems pretty safe.

davidism commented 8 months ago

I use the empty string "" in another API library I maintain, which isn't otherwise valid as a form field name.