Skip to content

Commit

Permalink
Add a very basic guard against virtual fields which reference themself
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 14, 2017
1 parent 3f4d6de commit 8711473
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/core/qgsvectorlayerfeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() )
Expand Down
5 changes: 5 additions & 0 deletions tests/src/python/test_qgsvectorlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 8711473

Please sign in to comment.