Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Request.get_json() in Werkzeug 2.1.0 breaks empty forms #511

Closed
jwag956 opened this issue Mar 31, 2022 · 3 comments
Closed

Update to Request.get_json() in Werkzeug 2.1.0 breaks empty forms #511

jwag956 opened this issue Mar 31, 2022 · 3 comments

Comments

@jwag956
Copy link
Contributor

jwag956 commented Mar 31, 2022

Similar to #510 - the get_json() change in Werkzeug 2.1.0 pallets/werkzeug#2339 breaks any empty submitted form (not json).
From form.py:

 def wrap_formdata(self, form, formdata):
            if formdata is _Auto:
                if _is_submitted():
                    if request.files:
                        return CombinedMultiDict((request.files, request.form))
                    elif request.form:
                        return request.form
                    elif request.get_json():
                        return ImmutableMultiDict(request.get_json())

If the form is an empty ImmutableMultiDict - it falls into the get_json() code which is then checking that the content-type header has been set to application/json.

Possible solution would be to change elif request.get_json() to elif request.is_json()

Expected Behavior:

Empty form submits should be allowed as they were. In the case of an empty form - None should be returned from the wrapper.

Environment:

  • Python version: 3.8
  • Flask-WTF version: 1.0.0
  • Flask version: 2.1
@davidism
Copy link
Member

Will make a 1.0.1 release soon.

@davidism
Copy link
Member

Flask-WTF 1.0.1 is available: https://pypi.org/project/Flask-WTF/1.0.1/

@jwag956
Copy link
Contributor Author

jwag956 commented Mar 31, 2022

Thank you... thank you...

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants