@@ -272,25 +272,25 @@ def testCreateFeature(self):
272
272
# test with violated unique constraints
273
273
layer .setFieldConstraint (1 , QgsFieldConstraints .ConstraintUnique )
274
274
f = QgsVectorLayerUtils .createFeature (layer , attributes = {0 : 'test_1' , 1 : 123 })
275
- # since field 1 has Unique Constraint, it ignores value 123 that already has been set
276
- self .assertEqual (f .attributes (), ['test_1' , NULL , NULL ])
275
+ # since field 1 has Unique Constraint, it ignores value 123 that already has been set and sets to 128
276
+ self .assertEqual (f .attributes (), ['test_1' , 128 , NULL ])
277
277
layer .setFieldConstraint (0 , QgsFieldConstraints .ConstraintUnique )
278
278
# since field 0 and 1 already have values test_1 and 123, the output must be null
279
279
f = QgsVectorLayerUtils .createFeature (layer , attributes = {0 : 'test_1' , 1 : 123 })
280
- self .assertEqual (f .attributes (), [NULL , NULL , NULL ])
280
+ self .assertEqual (f .attributes (), ['test_4' , 128 , NULL ])
281
281
282
282
# test with violated unique constraints and default value expression providing unique value
283
283
layer .setDefaultValueDefinition (1 , QgsDefaultValue ('130' ))
284
284
f = QgsVectorLayerUtils .createFeature (layer , attributes = {0 : 'test_1' , 1 : 123 })
285
285
# since field 1 has Unique Constraint, it ignores value 123 that already has been set and adds the default value
286
- self .assertEqual (f .attributes (), [NULL , 130 , NULL ])
286
+ self .assertEqual (f .attributes (), ['test_4' , 130 , NULL ])
287
287
# fallback: test with violated unique constraints and default value expression providing already existing value
288
288
# add the feature with the default value:
289
289
self .assertTrue (layer .dataProvider ().addFeatures ([f ]))
290
- f = QgsVectorLayerUtils .createFeature (layer , attributes = {0 : 'test_2 ' , 1 : 123 })
290
+ f = QgsVectorLayerUtils .createFeature (layer , attributes = {0 : 'test_1 ' , 1 : 123 })
291
291
# since field 1 has Unique Constraint, it ignores value 123 that already has been set and adds the default value
292
292
# and since the default value providing an already existing value (130) it generates a unique value (next int: 131)
293
- self .assertEqual (f .attributes (), [NULL , 131 , NULL ])
293
+ self .assertEqual (f .attributes (), ['test_5' , 131 , NULL ])
294
294
layer .setDefaultValueDefinition (1 , QgsDefaultValue (None ))
295
295
296
296
def testDuplicateFeature (self ):
0 commit comments