Skip to content
Permalink
Browse files

right order of priorities

by getting the value - if it's unique, first getting the defaults before creating an unique value.

Fix #20067
  • Loading branch information
signedav committed Oct 15, 2018
1 parent 375afe5 commit d26848e97746ccab3a8ac5c0a9cc56db63e34501
Showing with 2 additions and 9 deletions.
  1. +2 −9 src/core/qgsvectorlayerutils.cpp
@@ -381,17 +381,10 @@ QgsFeature QgsVectorLayerUtils::createFeature( const QgsVectorLayer *layer, cons

// in order of priority:
// 1. passed attribute value and if field does not have a unique constraint like primary key
if ( attributes.contains( idx ) )
if ( attributes.contains( idx )
&& !( fields.at( idx ).constraints().constraints() & QgsFieldConstraints::ConstraintUnique ) )
{
v = attributes.value( idx );
if ( fields.at( idx ).constraints().constraints() & QgsFieldConstraints::ConstraintUnique
&& QgsVectorLayerUtils::valueExists( layer, idx, v ) )
{
// unique constraint violated
QVariant uniqueValue = QgsVectorLayerUtils::createUniqueValue( layer, idx, v );
if ( uniqueValue.isValid() )
v = uniqueValue;
}
checkUnique = false;
}

0 comments on commit d26848e

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