Skip to content
Permalink
Browse files

Fix errors when saving features with virtual fields present

Fixes #18784
  • Loading branch information
nyalldawson committed Sep 24, 2018
1 parent 9fcd4fd commit cc53af296c8b9b5cad3856ce16efd86b6617ed5d
Showing with 8 additions and 0 deletions.
  1. +8 −0 src/core/qgsvectorlayereditbuffer.cpp
@@ -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 )
@@ -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() );

0 comments on commit cc53af2

Please sign in to comment.
You can’t perform that action at this time.