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

MultiDict.update() ignores empty "iterable" values while iterating #699

Merged
merged 1 commit into from Aug 5, 2015

Conversation

joshfriend
Copy link
Contributor

I did this to fix flask-restful/flask-restful#380 which has been annoying me for some time.

If you try to call update on a MultiDict and the mapping passed to update has an empty iterable for the value mapped to a key, that value is ignored:

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

Regular dict:

>>> x = {'empty_list': []}
>>> y = {}
>>> y.update(x)
>>> y
{'empty_list': []}

I think I read the docs pretty closely and didn't see that ignoring empty iterable values was intentional.

@untitaker
Copy link
Contributor

The behavior is definetly underspecified, but I think it's the intended one. Since the value is a list, it will be interpreted as a list of values for this key, and since its empty, the key won't exist.

@untitaker
Copy link
Contributor

@joshfriend any update on this? I see that the behavior is quite inconsistent, however, I'd argue that for a MultiDict (ignoring the underlying data structures), it doesn't semantically make sense to differentiate between two states where a key has no values.

@joshfriend
Copy link
Contributor Author

@untitaker Docs updated. how's it look?

untitaker added a commit that referenced this pull request Aug 5, 2015
MultiDict.update() ignores empty "iterable" values while iterating
@untitaker untitaker merged commit 285e300 into pallets:master Aug 5, 2015
@untitaker
Copy link
Contributor

Thanks!

@joshfriend joshfriend deleted the md-ignores-empty-list branch August 5, 2015 19:13
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Empty JSON lists wiped out
2 participants