Skip to content

Commit cc53af2

Browse files
committedSep 24, 2018
Fix errors when saving features with virtual fields present
Fixes #18784
1 parent 9fcd4fd commit cc53af2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed
 

‎src/core/qgsvectorlayereditbuffer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "qgsvectorlayerundocommand.h"
2020
#include "qgsvectordataprovider.h"
2121
#include "qgsvectorlayer.h"
22+
#include "qgsvectorlayerutils.h"
2223

2324
//! populate two lists (ks, vs) from map - in reverse order
2425
template <class Key, class T> void mapToReversedLists( const QMap< Key, T > &map, QList<Key> &ks, QList<T> &vs )
@@ -606,6 +607,13 @@ bool QgsVectorLayerEditBuffer::commitChanges( QStringList &commitErrors )
606607
// this will preserve the order how they have been added e.g. (-1, -2, -3) while in the map they are ordered (-3, -2, -1)
607608
mapToReversedLists( mAddedFeatures, ids, featuresToAdd );
608609

610+
// we need to strip any extra attributes here -- e.g. virtual fields, which should
611+
// not be sent to the data provider. Refs #18784
612+
for ( int i = 0; i < featuresToAdd.count(); ++i )
613+
{
614+
QgsVectorLayerUtils::matchAttributesToFields( featuresToAdd[i], provider->fields() );
615+
}
616+
609617
if ( provider->addFeatures( featuresToAdd ) )
610618
{
611619
commitErrors << tr( "SUCCESS: %n feature(s) added.", "added features count", featuresToAdd.size() );

0 commit comments

Comments
 (0)
Please sign in to comment.