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

Empty JSON lists wiped out #380

Open
joshfriend opened this issue Jan 5, 2015 · 11 comments
Open

Empty JSON lists wiped out #380

joshfriend opened this issue Jan 5, 2015 · 11 comments
Assignees
Milestone

Comments

@joshfriend
Copy link
Member

@joshfriend joshfriend commented Jan 5, 2015

#261 introduced a bug where if an argument is an empty JSON list, it will be omitted from the argument collection.

@joshfriend joshfriend self-assigned this Jan 5, 2015
@joshfriend joshfriend added this to the 0.3.2 milestone Jan 5, 2015
@joshfriend
Copy link
Member Author

@joshfriend joshfriend commented Jan 30, 2015

Also wipes out all the but the first element of non-empty lists

Loading

@joshfriend
Copy link
Member Author

@joshfriend joshfriend commented Feb 2, 2015

Appears to be a regression introduced by #261

Loading

@joshfriend joshfriend removed this from the 0.3.2 milestone Feb 26, 2015
@joshfriend joshfriend added this to the 0.3.3 milestone Feb 26, 2015
@joshfriend joshfriend added this to the 0.3.3 milestone Feb 26, 2015
@joshfriend joshfriend removed this from the 0.3.2 milestone Feb 26, 2015
@joshfriend
Copy link
Member Author

@joshfriend joshfriend commented Feb 28, 2015

>>> from werkzeug.datastructures import MultiDict
>>> x = {'empty_list': []}
>>> y = MultiDict()
>>> y
MultiDict([])
>>> y.update(x)
>>> y
MultiDict([])
>>> y['empty_list'] = []
>>> y
MultiDict([('empty_list', [])])

Loading

@joshfriend
Copy link
Member Author

@joshfriend joshfriend commented Feb 28, 2015

Only happens when using the default location=('json', 'values'). Works fine when location='json'

Loading

@joshfriend joshfriend removed this from the 0.3.3 milestone May 21, 2015
@joshfriend joshfriend added this to the 0.3.4 milestone May 21, 2015
@joshfriend joshfriend added this to the 0.3.4 milestone May 21, 2015
@joshfriend joshfriend removed this from the 0.3.3 milestone May 21, 2015
@joshfriend joshfriend removed this from the 0.3.4 milestone Jul 20, 2015
@joshfriend joshfriend added this to the 0.3.5 milestone Jul 20, 2015
@joshfriend joshfriend added this to the 0.3.5 milestone Jul 20, 2015
@joshfriend joshfriend removed this from the 0.3.4 milestone Jul 20, 2015
@joshfriend joshfriend closed this in 939f4c2 Aug 1, 2015
@odarbelaeze
Copy link

@odarbelaeze odarbelaeze commented Jan 23, 2018

Looks like this doesn't work anymore with 0.3.6, a list of strings passed in the json is interpreted like ['t', 'h', 'i', 's'] instead of ['this'].

Loading

@Kokosso
Copy link

@Kokosso Kokosso commented Feb 10, 2018

@odarbelaeze
Hey, I add one string into reqparse.py.
value = ''.join(value).

Loading

@gabll
Copy link

@gabll gabll commented Feb 15, 2018

I confirm, while putting location='json' was working in 0.3.5 as @joshfriend mentioned, in 0.3.6 isn't enough and it splits the string.

Loading

@ArtemChekunov
Copy link

@ArtemChekunov ArtemChekunov commented Mar 15, 2018

Hello @joshfriend could you reopen the issue.
In 0.3.6 it is not works

Loading

@joshfriend joshfriend reopened this Mar 15, 2018
@mayasankar
Copy link

@mayasankar mayasankar commented Jun 25, 2018

A workaround I found is using the options required=False, type=str, action='append', default=[] if you want a list of strings. However, this does not distinguish between having value [] and not being specified.

Loading

@stefanbschneider
Copy link

@stefanbschneider stefanbschneider commented Feb 6, 2019

Dosn't work for me. I get TypeError: sequence item 1: expected str instance, list found when using [] as default, even though I specify type=str.

Loading

@d6tdev
Copy link

@d6tdev d6tdev commented Dec 1, 2019

Doesn't seem to working as expected. I would expect it type check for a list and if a string is json posted it fails validation. Instead it converts string to list.

two cases: 1) post 'appid' (expect it to fail) and 2) post ['appid', 'userid'] (expect it to give me a list)

With type=list, location='json' get ['a', 'p', 'p', 'i', 'd'] (not what I want, it passed type check instead of fail) and ['appid', 'userid'] (what I want).

With type=list, location='json', action='append' get [['a', 'p', 'p', 'i', 'd']] (not what I want) and [['appid', 'userid']] (also not what I want).

With type=str, location='json', action='append' get ['appid'] (what I want although it really should have failed) but ["['appid', 'userid']"] (not what I want)

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

8 participants