Skip to content

Commit

Permalink
Fix errors when saving features with virtual fields present
Browse files Browse the repository at this point in the history
Fixes #18784
  • Loading branch information
nyalldawson committed Sep 24, 2018
1 parent 9fcd4fd commit cc53af2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/core/qgsvectorlayereditbuffer.cpp
Expand Up @@ -19,6 +19,7 @@
#include "qgsvectorlayerundocommand.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"
#include "qgsvectorlayerutils.h"

//! populate two lists (ks, vs) from map - in reverse order
template <class Key, class T> void mapToReversedLists( const QMap< Key, T > &map, QList<Key> &ks, QList<T> &vs )
Expand Down Expand Up @@ -606,6 +607,13 @@ bool QgsVectorLayerEditBuffer::commitChanges( QStringList &commitErrors )
// 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)
mapToReversedLists( mAddedFeatures, ids, featuresToAdd );

// we need to strip any extra attributes here -- e.g. virtual fields, which should
// not be sent to the data provider. Refs #18784
for ( int i = 0; i < featuresToAdd.count(); ++i )
{
QgsVectorLayerUtils::matchAttributesToFields( featuresToAdd[i], provider->fields() );
}

if ( provider->addFeatures( featuresToAdd ) )
{
commitErrors << tr( "SUCCESS: %n feature(s) added.", "added features count", featuresToAdd.size() );
Expand Down

0 comments on commit cc53af2

Please sign in to comment.