Skip to content

Commit 0616784

Browse files
committed
[processing] Fix exception when clicking alg with distance param in history dialog
(cherry-picked from 1621402)
1 parent e80cd7a commit 0616784

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

python/plugins/processing/gui/NumberInputPanel.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ def __init__(self, param):
143143
super(NumberInputPanel, self).__init__(None)
144144
self.setupUi(self)
145145

146+
self.layer = None
147+
146148
self.spnValue.setExpressionsEnabled(True)
147149

148150
self.param = param
@@ -211,7 +213,8 @@ def __init__(self, param):
211213

212214
def setDynamicLayer(self, layer):
213215
try:
214-
self.btnDataDefined.setVectorLayer(self.getLayerFromValue(layer))
216+
self.layer = self.getLayerFromValue(layer)
217+
self.btnDataDefined.setVectorLayer(self.layer)
215218
except:
216219
pass
217220

@@ -221,7 +224,14 @@ def getLayerFromValue(self, value):
221224
value, ok = value.source.valueAsString(context.expressionContext())
222225
if isinstance(value, str):
223226
value = QgsProcessingUtils.mapLayerFromString(value, context)
224-
return value
227+
if value is None:
228+
return None
229+
230+
# need to return layer with ownership - otherwise layer may be deleted when context
231+
# goes out of scope
232+
new_layer = context.takeResultLayer(value.id())
233+
# if we got ownership, return that - otherwise just return the layer (which may be owned by the project)
234+
return new_layer if new_layer is not None else value
225235

226236
def getValue(self):
227237
if self.btnDataDefined is not None and self.btnDataDefined.isActive():

0 commit comments

Comments
 (0)