Skip to content

Commit

Permalink
avoid on duplicate user functions (fixes #13579)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Oct 17, 2015
1 parent 6496bc4 commit cc9c789
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion python/core/__init__.py
@@ -1,6 +1,7 @@
import inspect
import string
from qgis._core import *
from PyQt4.QtCore import QCoreApplication


def register_function(function, arg_count, group, usesgeometry=False, **kwargs):
Expand Down Expand Up @@ -66,7 +67,10 @@ def func(self, values, feature, parent):
register = kwargs.get('register', True)
if register and QgsExpression.isFunctionName(name):
if not QgsExpression.unregisterFunction(name):
raise TypeError("Unable to unregister function")
msgtitle = QCoreApplication.translate("UserExpressions", "User expressions")
msg = QCoreApplication.translate("UserExpressions", "The user expression {0} already exists and could not be unregistered.").format(name)
QgsMessageLog.logMessage(msg + "\n", msgtitle, QgsMessageLog.WARNING)
return None

function.__name__ = name
helptext = helptemplate.safe_substitute(name=name, doc=helptext)
Expand Down
2 changes: 1 addition & 1 deletion python/user.py
Expand Up @@ -68,5 +68,5 @@ def func(value1, feature, parent):
except ImportError:
# We get a import error and crash for some reason even if we make the expressions package
# TODO Fix the crash on first load with no expressions folder
# But for now it's not the end of the world if it doesn't laod the first time
# But for now it's not the end of the world if it doesn't load the first time
pass

0 comments on commit cc9c789

Please sign in to comment.