Skip to content
Permalink
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 26, 2018
1 parent 49846de commit 703a6be1172dcda1e73a84d6710fb319a20ff96d
@@ -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(self.tr('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)
self.field_indices.append(index)
if index >= 0:
self.field_indices.append(index)

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

0 comments on commit 703a6be

Please sign in to comment.
You can’t perform that action at this time.