Skip to content

Commit 703a6be

Browse files
committed
[processing] Don't abort when missing field name specified in
delete columns algorithm Fixes #19256 (cherry-picked from 85fba79)
1 parent 49846de commit 703a6be

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

python/plugins/processing/algs/qgis/DeleteColumn.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,22 @@ def outputName(self):
6868

6969
def prepareAlgorithm(self, parameters, context, feedback):
7070
self.fields_to_delete = self.parameterAsFields(parameters, self.COLUMNS, context)
71-
return True
71+
72+
source = self.parameterAsSource(parameters, 'INPUT', context)
73+
if source is not None:
74+
for f in self.fields_to_delete:
75+
index = source.fields().lookupField(f)
76+
if index < 0:
77+
feedback.pushInfo(self.tr('Field “{}” does not exist in input layer').format(f))
78+
79+
return super().prepareAlgorithm(parameters, context, feedback)
7280

7381
def outputFields(self, input_fields):
7482
# loop through twice - first we need to build up a list of original attribute indices
7583
for f in self.fields_to_delete:
7684
index = input_fields.lookupField(f)
77-
self.field_indices.append(index)
85+
if index >= 0:
86+
self.field_indices.append(index)
7887

7988
# important - make sure we remove from the end so we aren't changing used indices as we go
8089
self.field_indices.sort(reverse=True)

python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2143,7 +2143,7 @@ tests:
21432143
- algorithm: qgis:deletecolumn
21442144
name: Delete columns (multiple)
21452145
params:
2146-
COLUMN: floatval;name
2146+
COLUMN: floatval;name;xxxxxx
21472147
INPUT:
21482148
name: polys.gml
21492149
type: vector

0 commit comments

Comments
 (0)