Skip to content
Permalink
Browse files

Add out layer to registry before its update.

Useful only in case of use waterfall aggregate functions because they get
layer from registry basing on layer scope.

Fixes #17300
(#5950)
  • Loading branch information
luipir authored and strk committed Jan 24, 2018
1 parent 845bf29 commit 1c34b2558999e42f7b3d81865e2bfed560ce9856
Showing with 24 additions and 1 deletion.
  1. +24 −1 python/plugins/processing/algs/qgis/FieldsCalculator.py
@@ -26,7 +26,17 @@
__revision__ = '$Format:%H$'

from qgis.PyQt.QtCore import QVariant
from qgis.core import QgsExpression, QgsExpressionContext, QgsExpressionContextUtils, QgsFeature, QgsField, QgsDistanceArea, QgsProject, GEO_NONE
from qgis.core import (
QgsExpression,
QgsExpressionContext,
QgsExpressionContextUtils,
QgsFeature,
QgsField,
QgsDistanceArea,
QgsProject,
QgsMapLayerRegistry,
GEO_NONE
)
from qgis.utils import iface
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
@@ -122,6 +132,14 @@ def processAlgorithm(self, progress):
raise GeoAlgorithmExecutionException(
self.tr('Evaluation error: %s' % exp.evalErrorString()))

# add layer to registry to fix https://issues.qgis.org/issues/17300
# it is necessary only for aggregate expressions that verify that layer
# is registered
removeRegistryAfterEvaluation = False
if not QgsMapLayerRegistry.instance().mapLayer(layer.id()):
removeRegistryAfterEvaluation = True
QgsMapLayerRegistry.instance().addMapLayer(layer, addToLegend=False)

outFeature = QgsFeature()
outFeature.initAttributes(len(fields))
outFeature.setFields(fields)
@@ -152,6 +170,11 @@ def processAlgorithm(self, progress):
progress.setPercentage(int(current * total))
del writer

# remove from registry if added for expression requirement
# see above comment about fix #17300
if removeRegistryAfterEvaluation:
QgsMapLayerRegistry.instance().removeMapLayer(layer)

if not calculationSuccess:
raise GeoAlgorithmExecutionException(
self.tr('An error occurred while evaluating the calculation '

0 comments on commit 1c34b25

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