Skip to content

Commit db1645c

Browse files
committedMar 14, 2019
[processing] Fix processing.runAndLoadResults
Fixes #21551
1 parent ab530e4 commit db1645c

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed
 

‎python/plugins/processing/gui/Postprocessing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ def handleAlgorithmResults(alg, context, feedback=None, showResults=True, parame
9696
scope = QgsExpressionContextScope()
9797
expcontext.appendScope(scope)
9898
for out in alg.outputDefinitions():
99+
if out.name() not in parameters:
100+
continue
99101
outValue = parameters[out.name()]
100102
if hasattr(outValue, "sink"):
101103
outValue = outValue.sink.valueAsString(expcontext)[0]

‎python/plugins/processing/tests/ProcessingGeneralTest.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
from qgis.core import (QgsApplication,
3333
QgsProcessing,
3434
QgsProcessingContext,
35-
QgsVectorLayer)
35+
QgsVectorLayer,
36+
QgsProject)
3637
from qgis.PyQt import sip
3738
from qgis.analysis import (QgsNativeAlgorithms)
3839
from qgis.testing import start_app, unittest
@@ -91,6 +92,26 @@ def testRun(self):
9192
gc.collect()
9293
self.assertTrue(sip.isdeleted(layer))
9394

95+
def testRunAndLoadResults(self):
96+
QgsProject.instance().removeAllMapLayers()
97+
context = QgsProcessingContext()
98+
99+
# try running an alg using processing.runAndLoadResults - ownership of result layer should be transferred to
100+
# project, and layer should be present in project
101+
res = processing.runAndLoadResults('qgis:buffer',
102+
{'DISTANCE': 1, 'INPUT': points(), 'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT},
103+
context=context)
104+
self.assertIn('OUTPUT', res)
105+
# output should be the layer path
106+
self.assertIsInstance(res['OUTPUT'], str)
107+
108+
self.assertEqual(context.layersToLoadOnCompletion()[res['OUTPUT']].project, QgsProject.instance())
109+
layer = QgsProject.instance().mapLayer(res['OUTPUT'])
110+
self.assertIsInstance(layer, QgsVectorLayer)
111+
112+
# Python should NOT have ownership
113+
self.assertFalse(sip.ispyowned(layer))
114+
94115

95116
if __name__ == '__main__':
96117
nose2.main()

0 commit comments

Comments
 (0)
Please sign in to comment.