Skip to content

Commit

Permalink
[processing] Don't abort when missing field name specified in
Browse files Browse the repository at this point in the history
delete columns algorithm

Fixes #19256

(cherry-picked from 85fba79)
  • Loading branch information
nyalldawson committed Jun 28, 2018
1 parent 49846de commit 703a6be
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions python/plugins/processing/algs/qgis/DeleteColumn.py
Expand Up @@ -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)
Expand Down
Expand Up @@ -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
Expand Down

0 comments on commit 703a6be

Please sign in to comment.