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

Python 3.x and empty file (b'') using FieldStorageUploadConverter #101

Open
antoniojesvs opened this issue Dec 3, 2015 · 2 comments
Open

Comments

@antoniojesvs
Copy link

Using Pyramid and Python 3.4.
When I leave an input type="file" name="file" empty, the request.POST has {'file': b' '}.
b' ' is iterable, so formencode raises singleValueExpected=_('Please provide only one value')

Python 3.4.3 (default, Jul 28 2015, 18:20:59) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from formencode import Schema, validators
>>> class FileSchema(Schema):
...     file = validators.FieldStorageUploadConverter()
... 
>>> FileSchema().to_python({"file": b''})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/aj/.virtualenvs/marketplace/lib/python3.4/site-packages/formencode/api.py", line 476, in to_python
    value = tp(value, state)
  File "/home/aj/.virtualenvs/marketplace/lib/python3.4/site-packages/formencode/schema.py", line 217, in _convert_to_python
    value_dict, state, error_dict=errors)
formencode.api.Invalid: file: Please provide only one value
>>>
@lambacck
Copy link
Contributor

lambacck commented Dec 5, 2015

We are explicitly checking for basestring, which seems like it's not the right thing to do on Python 3. I'm investigating what other string-likes we need in order to make it work.

valos added a commit to valos/formencode that referenced this issue Dec 17, 2018
@jvanasco
Copy link
Contributor

jvanasco commented May 1, 2020

this got detected by one of my test suites today. it was a pain to figure out. the fix deployed by @valos above passed out tests without triggering new issues.

jvanasco added a commit to jvanasco/formencode that referenced this issue Sep 25, 2020
lambacck added a commit that referenced this issue Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants