Skip to content

Commit d26848e

Browse files
committedOct 15, 2018
right order of priorities
by getting the value - if it's unique, first getting the defaults before creating an unique value. Fix #20067
1 parent 375afe5 commit d26848e

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed
 

‎src/core/qgsvectorlayerutils.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -381,17 +381,10 @@ QgsFeature QgsVectorLayerUtils::createFeature( const QgsVectorLayer *layer, cons
381381

382382
// in order of priority:
383383
// 1. passed attribute value and if field does not have a unique constraint like primary key
384-
if ( attributes.contains( idx ) )
384+
if ( attributes.contains( idx )
385+
&& !( fields.at( idx ).constraints().constraints() & QgsFieldConstraints::ConstraintUnique ) )
385386
{
386387
v = attributes.value( idx );
387-
if ( fields.at( idx ).constraints().constraints() & QgsFieldConstraints::ConstraintUnique
388-
&& QgsVectorLayerUtils::valueExists( layer, idx, v ) )
389-
{
390-
// unique constraint violated
391-
QVariant uniqueValue = QgsVectorLayerUtils::createUniqueValue( layer, idx, v );
392-
if ( uniqueValue.isValid() )
393-
v = uniqueValue;
394-
}
395388
checkUnique = false;
396389
}
397390

0 commit comments

Comments
 (0)
Please sign in to comment.