Skip to content

Instantly share code, notes, and snippets.

@docapotamus
Created January 9, 2017 18:48
Show Gist options
  • Save docapotamus/22040ea7791a9725bbbe36ef36a12179 to your computer and use it in GitHub Desktop.
Save docapotamus/22040ea7791a9725bbbe36ef36a12179 to your computer and use it in GitHub Desktop.
FileField fails validation when empty (Flask-WTF 0.14)
# Work successfully in my tests
resp = self.client.post(
url_for('posts.post'),
data={
'body': 'Test',
'upload': '',
},
follow_redirects=True
)
# However if I upload the code using multipart-form-data (taken from Firefox inspector `Params`, same issue in Chrome)
"""
Content-Type: multipart/form-data; boundary=---------------------------191598866112415400995302957
Content-Length: 651
-----------------------------191598866112415400995302957
Content-Disposition: form-data; name="body"
Test
-----------------------------191598866112415400995302957
Content-Disposition: form-data; name="csrf_token"
IjY4YTZmYjNmNWM4MWJlNmVjMjc3Y2Y4YjBiMTM1Nzk3YTdhMGZkNjci.C1VoNg.8Pg2PvN8N00Phc527XVBXjAn9rs
-----------------------------191598866112415400995302957
Content-Disposition: form-data; name="permission"
0
-----------------------------191598866112415400995302957
Content-Disposition: form-data; name="upload"; filename=""
Content-Type: application/octet-stream
-----------------------------191598866112415400995302957--
"""
# This has only started happening since since Flask 0.14 upgrade
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment