Skip to content

Commit

Permalink
Fix crash in merge features
Browse files Browse the repository at this point in the history
Fix #5122

Introduced by #47822
  • Loading branch information
elpaso authored and github-actions[bot] committed Jan 6, 2023
1 parent d168cf8 commit 1975680
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -10421,7 +10421,19 @@ void QgisApp::mergeSelectedFeatures()
vl->dataProvider()->pkAttributeIndexes().contains( vl->fields().fieldOriginIndex( i ) );

if ( isPrimaryKey && !isDefaultValue )
mergeFeatureId = val.toLongLong();
{
const QgsField pkField { vl->fields().field( i ) };
QgsFeatureRequest request;
request.setFlags( QgsFeatureRequest::Flag::NoGeometry );
request.setSubsetOfAttributes( QStringList() << pkField.name(), vl->fields( ) );
request.setFilterExpression( QgsExpression::createFieldEqualityExpression( pkField.name(), val, pkField.type( ) ) );
QgsFeature f;
QgsFeatureIterator featureIterator = vl->getFeatures( request );
if ( featureIterator.nextFeature( f ) )
{
mergeFeatureId = f.id( );
}
}

// convert to destination data type
if ( !isDefaultValue && !vl->fields().at( i ).convertCompatible( val, &errorMessage ) )
Expand Down

0 comments on commit 1975680

Please sign in to comment.