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 authored and github-actions committed Apr 21, 2021
1 parent 21fab96 commit 3a25f8ad64bf416bc47b1b19b0f1981520cf6a74
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 3a25f8a

Please sign in to comment.