๐Ÿ› Fix support for nullable form fields by maxclaey ยท Pull Request #12502 ยท fastapi/fastapi

@maxclaey

Fix support for nullable form fields, differentiate between unspecified and specified as None. See related bug ticket #12245

@maxclaey

@maxclaey

@maxclaey maxclaey changed the title Fix support for nullable form fields ๐Ÿ› Fix support for nullable form fields

Oct 21, 2024

@KennyKnecht

tonyay163

@PidgeyBE

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?

@heckad

@github-actions

This pull request has a merge conflict that needs to be resolved.

YuriiMotov

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?

@YuriiMotov

@maxclaey, thank you for your interest and efforts!
Could you please resolve the merge conflict?

@github-actions

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.

@creative-being

This comment was marked as spam.

8 similar comments

@creative-being

This comment was marked as spam.

@creative-being

This comment was marked as spam.

@creative-being

This comment was marked as spam.

@creative-being

This comment was marked as spam.

@creative-being

This comment was marked as spam.

@creative-being

This comment was marked as spam.

@creative-being

This comment was marked as spam.

@creative-being

This comment was marked as spam.