Skip to content

Commit

Permalink
right order of priorities
Browse files Browse the repository at this point in the history
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 d26848e
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/core/qgsvectorlayerutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit d26848e

Please sign in to comment.