diff --git a/onadata/libs/serializers/geojson_serializer.py b/onadata/libs/serializers/geojson_serializer.py index 7e7e4dc3f6..54fa9a7370 100644 --- a/onadata/libs/serializers/geojson_serializer.py +++ b/onadata/libs/serializers/geojson_serializer.py @@ -141,9 +141,10 @@ def to_representation(self, instance): points = instance.json.get(geo_field) if geo_field in geotrace_xpaths or geo_field in polygon_xpaths: value = get_values_matching_key(instance.json, geo_field) + # handle empty geoms try: points = next(value) - except TypeError: + except StopIteration: points = None geometry = ( geometry_from_string(points, simple_style) diff --git a/onadata/libs/utils/dict_tools.py b/onadata/libs/utils/dict_tools.py index fe796c6632..9a37cc931e 100644 --- a/onadata/libs/utils/dict_tools.py +++ b/onadata/libs/utils/dict_tools.py @@ -22,8 +22,14 @@ def _get_values(doc, key): yield item elif isinstance(v, list): for i in v: - for j in _get_values(i, key): - yield j + if isinstance(i, (dict, list)): + try: + for j in _get_values(i, key): + yield j + except StopIteration: + continue + elif i == key: + yield i return _get_values(doc, key)