Skip to content

Commit

Permalink
Add safety check for field name in StatisticsByCategories
Browse files Browse the repository at this point in the history
So far we would only get a KeyError for -1
  • Loading branch information
m-kuhn committed Apr 20, 2021
1 parent 0eee27f commit 0073ab7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions python/plugins/processing/algs/qgis/StatisticsByCategories.py
Expand Up @@ -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):
Expand Down

0 comments on commit 0073ab7

Please sign in to comment.