Skip to content
Permalink
Browse files
Add safety check for field name in StatisticsByCategories
So far we would only get a KeyError for -1
  • Loading branch information
m-kuhn committed Apr 20, 2021
1 parent 0eee27f commit 0073ab76e82e54efe7044a8d3f5bec1ad0ecc083
Showing with 6 additions and 2 deletions.
  1. +6 −2 python/plugins/processing/algs/qgis/StatisticsByCategories.py
@@ -104,11 +104,15 @@ def processAlgorithm(self, parameters, context, feedback):
value_field = source.fields().at(value_field_index)
else:
value_field = None
category_field_indexes = [source.fields().lookupField(n) for n in category_field_names]
category_field_indexes = list()

# generate output fields
fields = QgsFields()
for c in category_field_indexes:
for field_name in category_field_names:
c = source.fields().lookupField(field_name)
if c == -1:
raise QgsProcessingException(self.tr(f'Field "{field_name}" does not exist.'))
category_field_indexes.append(c)
fields.append(source.fields().at(c))

def addField(name):

0 comments on commit 0073ab7

Please sign in to comment.