mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-18 00:03:05 -04:00
[processing] Fix crash in extract by attribute when field name does not exist
Fixes #19531
This commit is contained in:
parent
9e0860637d
commit
4acef1efbf
@ -130,6 +130,9 @@ class SelectByAttribute(QgisAlgorithm):
|
||||
fields = layer.fields()
|
||||
|
||||
idx = layer.fields().lookupField(fieldName)
|
||||
if idx < 0:
|
||||
raise QgsProcessingException(self.tr("Field '{}' was not found in layer").format(fieldName))
|
||||
|
||||
fieldType = fields[idx].type()
|
||||
|
||||
if fieldType != QVariant.String and operator in self.STRING_OPERATORS:
|
||||
|
@ -119,6 +119,9 @@ class AlgorithmsTest(object):
|
||||
exec(('\n'.join(defs['expectedFailure'][:-1])), globals(), locals())
|
||||
expectFailure = eval(defs['expectedFailure'][-1])
|
||||
|
||||
if 'expectedException' in defs:
|
||||
expectFailure = True
|
||||
|
||||
# ignore user setting for invalid geometry handling
|
||||
context = QgsProcessingContext()
|
||||
context.setProject(QgsProject.instance())
|
||||
|
Binary file not shown.
@ -2086,6 +2086,20 @@ tests:
|
||||
name: expected/extract_by_attribute_not_null.gml
|
||||
type: vector
|
||||
|
||||
- algorithm: native:extractbyattribute
|
||||
name: Extract by attribute (bad field)
|
||||
params:
|
||||
FIELD: notafield
|
||||
INPUT:
|
||||
name: polys.gml
|
||||
type: vector
|
||||
OPERATOR: '9'
|
||||
results:
|
||||
OUTPUT:
|
||||
name: expected/failure.gml
|
||||
type: vector
|
||||
expectedException: true
|
||||
|
||||
- algorithm: native:extractbyattribute
|
||||
name: Extract by attribute (starts with)
|
||||
params:
|
||||
|
@ -101,8 +101,10 @@ QVariantMap QgsExtractByAttributeAlgorithm::processAlgorithm( const QVariantMap
|
||||
std::unique_ptr< QgsFeatureSink > nonMatchingSink( parameterAsSink( parameters, QStringLiteral( "FAIL_OUTPUT" ), context, nonMatchingSinkId, source->fields(),
|
||||
source->wkbType(), source->sourceCrs() ) );
|
||||
|
||||
|
||||
int idx = source->fields().lookupField( fieldName );
|
||||
if ( idx < 0 )
|
||||
throw QgsProcessingException( QObject::tr( "Field '%1' was not found in INPUT source" ).arg( fieldName ) );
|
||||
|
||||
QVariant::Type fieldType = source->fields().at( idx ).type();
|
||||
|
||||
if ( fieldType != QVariant::String && ( op == BeginsWith || op == Contains || op == DoesNotContain ) )
|
||||
|
Loading…
x
Reference in New Issue
Block a user