Skip to content
Browse files
[processing] Don't abort when missing field name specified in
delete columns algorithm

Fixes #19256

(cherry-picked from 85fba79)
  • Loading branch information
nyalldawson committed Jun 28, 2018
1 parent 49846de commit 703a6be1172dcda1e73a84d6710fb319a20ff96d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
@@ -68,13 +68,22 @@ def outputName(self):

def prepareAlgorithm(self, parameters, context, feedback):
self.fields_to_delete = self.parameterAsFields(parameters, self.COLUMNS, context)
return True

source = self.parameterAsSource(parameters, 'INPUT', context)
if source is not None:
for f in self.fields_to_delete:
index = source.fields().lookupField(f)
if index < 0:
feedback.pushInfo('Field “{}” does not exist in input layer').format(f))

return super().prepareAlgorithm(parameters, context, feedback)

def outputFields(self, input_fields):
# loop through twice - first we need to build up a list of original attribute indices
for f in self.fields_to_delete:
index = input_fields.lookupField(f)
if index >= 0:

# important - make sure we remove from the end so we aren't changing used indices as we go
@@ -2143,7 +2143,7 @@ tests:
- algorithm: qgis:deletecolumn
name: Delete columns (multiple)
COLUMN: floatval;name
COLUMN: floatval;name;xxxxxx
name: polys.gml
type: vector

0 comments on commit 703a6be

Please sign in to comment.