Skip to content
Permalink
Browse files
Merge pull request #42869 from m-kuhn/statsbycaterror
Add safety check for field name in StatisticsByCategories
  • Loading branch information
m-kuhn committed Apr 21, 2021
2 parents 028f663 + 6a83a2f commit 42b461b615aaefc37a44137072338ac4b430a7fb
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('Field "{field_name}" does not exist.').format(field_name=field_name))
category_field_indexes.append(c)
fields.append(source.fields().at(c))

def addField(name):

0 comments on commit 42b461b

Please sign in to comment.