Skip to content

Conversation

@leifurhauks
Copy link

With Python 3.5, using sparse fieldsets causes a RuntimeError: OrderedDict mutated during iteration.

This patch fixes the bug, in SparseFieldsetMixin, by iterating over a copy of the OrderedDict, so that the original may be modified in the loop.

The OrderedDict in question is the underlying OrderedDict of the BindingDict returned by the fields property on Serializer.

If curious, see section 4.10.1 of the python standard library docs for more information about why this RuntimeError was being thrown in the first place.

With Python 3.5, using sparse fieldsets causes a `RuntimeError:
OrderedDict mutated during iteration`. This patch fixes the bug,
in `SparseFieldsetMixin`, by iterating over a copy of the `OrderedDict`,
so that the original may be modified in the loop.

The `OrderedDict` in question is the underlying `OrderedDict` of the
`BindingDict` returned by the `fields` property on `Serializer`.

If curious, see section
[4.10.1](https://docs.python.org/3/library/stdtypes.html#dictionary-view-objects)
of the python standard library docs for more information about
why this RuntimeError was being thrown in the first place.
jsenecal added a commit that referenced this pull request Nov 24, 2015
Fix sparse fieldset RuntimeError under python3.5
@jsenecal jsenecal merged commit cbd4bfa into django-json-api:develop Nov 24, 2015
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

Successfully merging this pull request may close these issues.

2 participants