Skip to content
Browse files

[processing] Don't hold on to algorithm instances for menu items

Instead, only store references to the algorithm id string, and
use this to retrieve algorithms when the actions are triggered.

This avoids errors caused by the algorithm instances being
removed, e.g. due to plugin removal or reload of providers
(e.g. by opening options dialog).

Fixes #19070
  • Loading branch information
nyalldawson committed May 31, 2018
1 parent 59d425c commit 1d62d106fbfaf975e38cbc83af8bc012f8813e53
Showing with 15 additions and 5 deletions.
  1. +15 −5 python/plugins/processing/gui/
@@ -189,9 +189,10 @@ def addAlgorithmEntry(alg, menuName, submenuName, actionText=None, icon=None, ad
alg_title = QgsStringUtils.capitalize(alg.displayName(), QgsStringUtils.TitleCase)
actionText = alg_title + QCoreApplication.translate('Processing', '…')
action = QAction(icon or alg.icon(), actionText, iface.mainWindow())
action.triggered.connect(lambda: _executeAlgorithm(alg))
action.setObjectName("mProcessingUserMenu_%s" %
alg_id =
action.triggered.connect(lambda: _executeAlgorithm(alg_id))
action.setObjectName("mProcessingUserMenu_%s" % alg_id)

if menuName:
menu = getMenu(menuName, iface.mainWindow().menuBar())
@@ -225,11 +226,20 @@ def removeAlgorithmEntry(alg, menuName, submenuName, delButton=True):

def _executeAlgorithm(alg):
def _executeAlgorithm(alg_id):
alg = QgsApplication.processingRegistry().createAlgorithmById(alg_id)
if alg is None:
dlg = MessageDialog()
dlg.setTitle('Missing Algorithm'))
dlg.setMessage('The algorithm "{}" is no longer available. (Perhaps a plugin was uninstalled?)').format(alg_id))

ok, message = alg.canExecute()
if not ok:
dlg = MessageDialog()
dlg.setTitle('Missing dependency'))
dlg.setTitle('Missing Dependency'))
dlg.setMessage('<h3>Missing dependency. This algorithm cannot '
'be run :-( </h3>\n{0}').format(message))

0 comments on commit 1d62d10

Please sign in to comment.
You can’t perform that action at this time.