mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-31 00:03:42 -04:00
Add a very basic guard against virtual fields which reference themself
This commit is contained in:
parent
3f4d6de54b
commit
8711473b7f
@ -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 @@ class TestQgsVectorLayer(unittest.TestCase, FeatureSourceTestCase):
|
||||
|
||||
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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user