Skip to content
Permalink
Browse files

[processing] Don't throw an exception if an expression cannot

be prepared

There's cases where this happens without reflecting an invalid
expression. So we can try to prepare, but not abort if the
preparation fails.

Fixes #18103
  • Loading branch information
nyalldawson committed Feb 15, 2018
1 parent e0b1d37 commit a8110369a80a4110aaa667656f30c95be1a2a33d
@@ -123,9 +123,7 @@ def processAlgorithm(self, parameters, context, feedback):
if layer is not None:
exp_context.appendScope(QgsExpressionContextUtils.layerScope(layer))

if not expression.prepare(exp_context):
raise QgsProcessingException(
self.tr('Evaluation error: {0}').format(expression.parserErrorString()))
expression.prepare(exp_context)

features = source.getFeatures()
total = 100.0 / source.featureCount() if source.featureCount() else 0
@@ -116,9 +116,7 @@ def processAlgorithm(self, parameters, context, feedback):
raise QgsProcessingException(expression.parserErrorString())

expressionContext = self.createExpressionContext(parameters, context, source)
if not expression.prepare(expressionContext):
raise QgsProcessingException(
self.tr('Evaluation error: {0}').format(expression.evalErrorString()))
expression.prepare(expressionContext)

fields = QgsFields()
fields.append(QgsField('id', QVariant.Int, '', 10, 0))

0 comments on commit a811036

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