๐ Fix support for nullable form fields by maxclaey ยท Pull Request #12502 ยท fastapi/fastapi
Fix support for nullable form fields, differentiate between unspecified and specified as None. See related bug ticket #12245
maxclaey
changed the title
Fix support for nullable form fields
๐ Fix support for nullable form fields
Hi @tiangolo,
I'm sorry to involve you here directly, but this fix/PR has been created over 5 months ago.
Since it covers basic functionality (support for nullable form fields) and unblocks CVE fixes, I was just wondering if there is a reason this work cannot be merged?
Comment on lines +720 to +722
| isinstance(field.field_info, params.Form) | ||
| and isinstance(value, str) # For type checks | ||
| and value == "" |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please clarify why you removed the or (is_sequence_field(field) and len(value) == 0) part from this condition?
Comment on lines +724 to +728
| # Empty strings in a form can be a representation of None values | ||
| _, error = field.validate(None, {}, loc=()) | ||
| # If None is an accepted value for this field, use that | ||
| if error is None: | ||
| value = None |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't really like this part.. Can we try getting this information from field annotation?
@maxclaey, thank you for your interest and efforts!
Could you please resolve the merge conflict?
As this PR has been waiting for the original user for a while but seems to be inactive, it's now going to be closed. But if there's anyone interested, feel free to create a new PR.
8 similar comments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters