Skip to content

Commit

Permalink
[processing] Don't throw an exception if an expression cannot
Browse files Browse the repository at this point in the history
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 a811036
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
4 changes: 1 addition & 3 deletions python/plugins/processing/algs/qgis/FieldsCalculator.py
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions python/plugins/processing/algs/qgis/RandomPointsPolygons.py
Expand Up @@ -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))
Expand Down

0 comments on commit a811036

Please sign in to comment.