Skip to content
Permalink
Browse files

Add a very basic guard against virtual fields which reference themself

  • Loading branch information
nyalldawson committed Jul 14, 2017
1 parent 3f4d6de commit 8711473b7f83d436eda5e7f4627a6090f2a227bc
Showing with 14 additions and 0 deletions.
  1. +9 −0 src/core/qgsvectorlayerfeatureiterator.cpp
  2. +5 −0 tests/src/python/test_qgsvectorlayer.py
@@ -617,6 +617,15 @@ void QgsVectorLayerFeatureIterator::prepareExpression( int fieldIdx )
exp->setAreaUnits( QgsProject::instance()->areaUnits() );

exp->prepare( mExpressionContext.get() );
Q_FOREACH ( const QString &col, exp->referencedColumns() )
{
if ( mSource->fields().lookupField( col ) == fieldIdx )
{
// circular reference - expression depends on column itself
delete exp;
return;
}
}
mExpressionFieldInfo.insert( fieldIdx, exp );

Q_FOREACH ( const QString &col, exp->referencedColumns() )
@@ -1609,6 +1609,11 @@ def test_ExpressionField(self):

self.assertEqual(layer.pendingFields().count(), cnt)

# expression field which references itself
idx = layer.addExpressionField('sum(test2)', QgsField('test2', QVariant.LongLong))
fet = next(layer.getFeatures())
self.assertEqual(fet['test2'], NULL)

def test_ExpressionFieldEllipsoidLengthCalculation(self):
#create a temporary layer
temp_layer = QgsVectorLayer("LineString?crs=epsg:3111&field=pk:int", "vl", "memory")

0 comments on commit 8711473

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