Skip to content

Commit 492ce0c

Browse files
committedJun 12, 2019
Recalculate "evaluate on update" default expressions always
... no mather what attributes are provided. Default values with evaluate on update should really just always be calculated. Fix #30164 Fix #29683
1 parent 3113a96 commit 492ce0c

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed
 

‎src/core/qgsvectorlayerutils.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,11 @@ QgsFeatureList QgsVectorLayerUtils::createFeatures( const QgsVectorLayer *layer,
507507

508508
// 2. client side default expression
509509
// note - deliberately not using else if!
510+
QgsDefaultValue defaultValueDefinition = layer->defaultValueDefinition( idx );
510511
if ( ( v.isNull() || ( hasUniqueConstraint
511-
&& uniqueValueCaches[ idx ].contains( v ) ) )
512-
&& layer->defaultValueDefinition( idx ).isValid() )
512+
&& uniqueValueCaches[ idx ].contains( v ) )
513+
|| defaultValueDefinition.applyOnUpdate() )
514+
&& defaultValueDefinition.isValid() )
513515
{
514516
// client side default expression set - takes precedence over all. Why? Well, this is the only default
515517
// which QGIS users have control over, so we assume that they're deliberately overriding any

‎tests/src/python/test_qgsvectorlayerutils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ def testCreateFeature(self):
263263
# we do not expect the default value expression to take precedence over the attribute map
264264
f = QgsVectorLayerUtils.createFeature(layer, attributes={0: 'a', 2: 6.0})
265265
self.assertEqual(f.attributes(), ['a', NULL, 6.0])
266+
# default value takes precedence if it's apply on update
267+
layer.setDefaultValueDefinition(2, QgsDefaultValue('3*4', True))
268+
f = QgsVectorLayerUtils.createFeature(layer, attributes={0: 'a', 2: 6.0})
269+
self.assertEqual(f.attributes(), ['a', NULL, 12.0])
266270
# layer with default value expression based on geometry
267271
layer.setDefaultValueDefinition(2, QgsDefaultValue('3*$x'))
268272
f = QgsVectorLayerUtils.createFeature(layer, g)

0 commit comments

Comments
 (0)
Please sign in to comment.