Skip to content

Commit

Permalink
Fix iteration over a mutating list
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-saeon committed Jul 5, 2018
1 parent 026b6df commit caf8044
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ckanext/metadata/jsonschema_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,26 @@
def validate(instance, schema):

def clear_empties(node):
"""
Recursively remove empty elements from the instance tree.
"""
if type(node) is dict:
# iterate over a copy of the dict's keys, as we are deleting keys during iteration
for element in node.keys():
clear_empties(node[element])
if not node[element]:
del node[element]
elif type(node) is list:
for element in node:
# iterate over a copy of the list, as we are deleting elements during iteration
for element in list(node):
clear_empties(element)
if not element:
node.remove(element)

def add_error(node, path, message):
"""
Add an error message to the error tree.
"""
if path:
element = path.popleft()
else:
Expand Down

0 comments on commit caf8044

Please sign in to comment.