Skip to content

Commit

Permalink
[processing] Fix crash when running model from file through qgis_process
Browse files Browse the repository at this point in the history
with the --json switch
  • Loading branch information
nyalldawson authored and github-actions[bot] committed Feb 9, 2021
1 parent a8b288d commit 7dca471
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/process/qgsprocess.cpp
Expand Up @@ -805,9 +805,13 @@ int QgsProcessingExec::execute( const QString &id, const QVariantMap &params, co
algorithmDetails.insert( QStringLiteral( "id" ), alg->id() );
addAlgorithmInformation( algorithmDetails, alg );
json.insert( QStringLiteral( "algorithm_details" ), algorithmDetails );
QVariantMap providerJson;
addProviderInformation( providerJson, alg->provider() );
json.insert( QStringLiteral( "provider_details" ), providerJson );

if ( alg->provider() )
{
QVariantMap providerJson;
addProviderInformation( providerJson, alg->provider() );
json.insert( QStringLiteral( "provider_details" ), providerJson );
}
}

std::unique_ptr< QgsProject > project;
Expand Down
17 changes: 17 additions & 0 deletions tests/src/python/test_qgsprocessexecutable.py
Expand Up @@ -249,6 +249,23 @@ def testModelRun(self):
self.assertIn('results', output.lower())
self.assertTrue(os.path.exists(output_file))

def testModelRunJson(self):
output_file = self.TMP_DIR + '/model_output2.shp'
rc, output, err = self.run_process(['run', TEST_DATA_DIR + '/test_model.model3', '--json', '--', 'FEATS={}'.format(TEST_DATA_DIR + '/polys.shp'), 'native:centroids_1:CENTROIDS={}'.format(output_file)])
if os.environ.get('TRAVIS', '') != 'true':
# Travis DOES have errors, due to QStandardPaths: XDG_RUNTIME_DIR not set warnings raised by Qt
self.assertFalse(err)
self.assertEqual(rc, 0)

res = json.loads(output)
self.assertIn('gdal_version', res)
self.assertIn('geos_version', res)
self.assertIn('proj_version', res)
self.assertIn('qt_version', res)
self.assertIn('qgis_version', res)
self.assertEqual(res['algorithm_details']['id'], 'Test model')
self.assertTrue(os.path.exists(output_file))


if __name__ == '__main__':
# look for qgis bin path
Expand Down

0 comments on commit 7dca471

Please sign in to comment.