Skip to content
Permalink
Browse files

[processing] Fix crash when running model from file through qgis_process

with the --json switch
  • Loading branch information
nyalldawson authored and github-actions committed Feb 9, 2021
1 parent a8b288d commit 7dca471ae7a3c10a43e6adf01031e450eb0d050b
Showing with 24 additions and 3 deletions.
  1. +7 −3 src/process/qgsprocess.cpp
  2. +17 −0 tests/src/python/test_qgsprocessexecutable.py
@@ -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;
@@ -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

0 comments on commit 7dca471

Please sign in to comment.