Commit d70b9dbf authored by Mark Caglienzi's avatar Mark Caglienzi
Browse files

Avoid 'RuntimeError: OrderedDict mutated during iteration' when creating a new user

parent f3a29a3d
......@@ -11,7 +11,11 @@ def reorder_fields(fields, order):
... ['b', 'c', 'a'])
OrderedDict([('b', 2), ('c', 3), ('a', 1)])
for key, v in fields.items():
old_fields = fields.copy()
# Iterate through old_fields, but remove fields from fields, which is the OrderedDict that
# gets returned, so to avoid 'RuntimeError: OrderedDict mutated during iteration'
for key, v in old_fields.items():
if key not in order:
del fields[key]
return OrderedDict(sorted(fields.items(), key=lambda k: order.index(k[0])))
......@@ -641,6 +641,8 @@ class UserCreateForm(UserForm):
# Add the new field to the key_order list of keys
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment