@@ -1163,7 +1163,9 @@ void TestQgsProcessingModelAlgorithm::modelExecution()
1163
1163
layerDef.destinationName = " my_dest" ;
1164
1164
modelInputs.insert ( " cx3:MY_OUT" , QVariant::fromValue ( layerDef ) );
1165
1165
QVariantMap childResults;
1166
- QVariantMap params = model2.parametersForChildAlgorithm ( model2.childAlgorithm ( QStringLiteral ( " cx1" ) ), modelInputs, childResults, expContext );
1166
+ QString error;
1167
+ QVariantMap params = model2.parametersForChildAlgorithm ( model2.childAlgorithm ( QStringLiteral ( " cx1" ) ), modelInputs, childResults, expContext, error );
1168
+ QVERIFY ( error.isEmpty () );
1167
1169
QCOMPARE ( params.value ( " DISSOLVE" ).toBool (), false );
1168
1170
QCOMPARE ( params.value ( " DISTANCE" ).toInt (), 271 );
1169
1171
QCOMPARE ( params.value ( " SEGMENTS" ).toInt (), 16 );
@@ -1218,7 +1220,8 @@ void TestQgsProcessingModelAlgorithm::modelExecution()
1218
1220
alg2c2.setAlgorithmId ( " native:centroids" );
1219
1221
alg2c2.addParameterSources ( " INPUT" , QgsProcessingModelChildParameterSources () << QgsProcessingModelChildParameterSource::fromChildOutput ( QStringLiteral ( " cx1" ), " OUTPUT" ) );
1220
1222
model2.addChildAlgorithm ( alg2c2 );
1221
- params = model2.parametersForChildAlgorithm ( model2.childAlgorithm ( " cx2" ), modelInputs, childResults, expContext );
1223
+ params = model2.parametersForChildAlgorithm ( model2.childAlgorithm ( " cx2" ), modelInputs, childResults, expContext, error );
1224
+ QVERIFY ( error.isEmpty () );
1222
1225
QCOMPARE ( params.value ( " INPUT" ).toString (), QStringLiteral ( " dest.shp" ) );
1223
1226
QCOMPARE ( params.value ( " OUTPUT" ).toString (), QStringLiteral ( " memory:Centroids" ) );
1224
1227
QCOMPARE ( params.count (), 2 );
@@ -1269,7 +1272,8 @@ void TestQgsProcessingModelAlgorithm::modelExecution()
1269
1272
alg2c3.setModelOutputs ( outputs3 );
1270
1273
1271
1274
model2.addChildAlgorithm ( alg2c3 );
1272
- params = model2.parametersForChildAlgorithm ( model2.childAlgorithm ( " cx3" ), modelInputs, childResults, expContext );
1275
+ params = model2.parametersForChildAlgorithm ( model2.childAlgorithm ( " cx3" ), modelInputs, childResults, expContext, error );
1276
+ QVERIFY ( error.isEmpty () );
1273
1277
QCOMPARE ( params.value ( " INPUT" ).toString (), QStringLiteral ( " dest.shp" ) );
1274
1278
QCOMPARE ( params.value ( " EXPRESSION" ).toString (), QStringLiteral ( " true" ) );
1275
1279
QVERIFY ( params.value ( " OUTPUT" ).canConvert <QgsProcessingOutputLayerDefinition>() );
@@ -1278,23 +1282,38 @@ void TestQgsProcessingModelAlgorithm::modelExecution()
1278
1282
QCOMPARE ( outDef.sink .staticValue ().toString (), QStringLiteral ( " memory:" ) );
1279
1283
QCOMPARE ( params.count (), 3 ); // don't want FAIL_OUTPUT set!
1280
1284
1285
+ // a child with an expression which is invalid
1286
+ QgsProcessingModelChildAlgorithm alg2c3a;
1287
+ alg2c3a.setChildId ( " cx3a" );
1288
+ alg2c3a.setAlgorithmId ( " native:extractbyexpression" );
1289
+ alg2c3a.setDescription ( " Extract by expression" );
1290
+ alg2c3a.addParameterSources ( " INPUT" , QgsProcessingModelChildParameterSources () << QgsProcessingModelChildParameterSource::fromExpression ( QStringLiteral ( " 1/'a'" ) ) );
1291
+ alg2c3a.addParameterSources ( " EXPRESSION" , QgsProcessingModelChildParameterSources () << QgsProcessingModelChildParameterSource::fromStaticValue ( " true" ) );
1292
+ alg2c3a.addParameterSources ( " OUTPUT" , QgsProcessingModelChildParameterSources () << QgsProcessingModelChildParameterSource::fromModelParameter ( " MY_OUT" ) );
1293
+
1294
+ model2.addChildAlgorithm ( alg2c3a );
1295
+ params = model2.parametersForChildAlgorithm ( model2.childAlgorithm ( " cx3a" ), modelInputs, childResults, expContext, error );
1296
+ QCOMPARE ( error, QStringLiteral ( " Could not evaluate expression for parameter INPUT for Extract by expression: Cannot convert 'a' to double" ) );
1297
+ model2.removeChildAlgorithm ( " cx3a" );
1298
+
1281
1299
// a child with an static output value
1282
1300
QgsProcessingModelChildAlgorithm alg2c4;
1283
1301
alg2c4.setChildId ( " cx4" );
1284
1302
alg2c4.setAlgorithmId ( " native:extractbyexpression" );
1285
1303
alg2c4.addParameterSources ( " OUTPUT" , QgsProcessingModelChildParameterSources () << QgsProcessingModelChildParameterSource::fromStaticValue ( " STATIC" ) );
1286
1304
model2.addChildAlgorithm ( alg2c4 );
1287
- params = model2.parametersForChildAlgorithm ( model2.childAlgorithm ( " cx4" ), modelInputs, childResults, expContext );
1305
+ params = model2.parametersForChildAlgorithm ( model2.childAlgorithm ( " cx4" ), modelInputs, childResults, expContext, error );
1306
+ QVERIFY ( error.isEmpty () );
1288
1307
QCOMPARE ( params.value ( " OUTPUT" ).toString (), QStringLiteral ( " STATIC" ) );
1289
1308
model2.removeChildAlgorithm ( " cx4" );
1290
1309
// expression based output value
1291
1310
alg2c4.addParameterSources ( " OUTPUT" , QgsProcessingModelChildParameterSources () << QgsProcessingModelChildParameterSource::fromExpression ( " 'A' || 'B'" ) );
1292
1311
model2.addChildAlgorithm ( alg2c4 );
1293
- params = model2.parametersForChildAlgorithm ( model2.childAlgorithm ( " cx4" ), modelInputs, childResults, expContext );
1312
+ params = model2.parametersForChildAlgorithm ( model2.childAlgorithm ( " cx4" ), modelInputs, childResults, expContext, error );
1313
+ QVERIFY ( error.isEmpty () );
1294
1314
QCOMPARE ( params.value ( " OUTPUT" ).toString (), QStringLiteral ( " AB" ) );
1295
1315
model2.removeChildAlgorithm ( " cx4" );
1296
1316
1297
-
1298
1317
variables = model2.variablesForChildAlgorithm ( " cx3" , context );
1299
1318
QCOMPARE ( variables.count (), 17 );
1300
1319
QCOMPARE ( variables.value ( " DIST" ).source .source (), QgsProcessingModelChildParameterSource::ModelParameter );
0 commit comments