I am trying to define a custom function in QGIS 2.8.1 that takes no arguments.

from qgis.core import *
from qgis.gui import *

@qgsfunction(args=0, group='Custom')
def test(value1, feature, parent):
    return 'test'

This results in a QGIS crash. What am I doing wrong?

  • Try removing value1 from the arg list
    – Nathan W
    May 7, 2015 at 21:20
  • Tried removing value1 from the arg. It stops the crash, but in the expression editor using $test gives "Eval Error: test() takes exactly 2 arguments (3 given)" May 8, 2015 at 3:52
  • hmm ok it should work. I will test it.
    – Nathan W
    May 8, 2015 at 4:07
  • 2
    I copy and pasted your code. It works fine in my OSGEO QGIS 2.8.1. You will need the value1 argument for removing the argument error. I think the problem is outside the function somewhere else in the py file of the function. What else do you have in the py file (folder ..qgis2\python or ..qgis2\python\expressions)? Can you try to move you code to a new clean py file in the ..qgis2\python folder and import the file in the startup.py
    – Jakob
    May 9, 2015 at 11:36
  • Thanks @Jakob. Clearing my .qgis2/python/expressions/ directory solved the problem. May 10, 2015 at 6:20

1 Answer 1


AS @Jakob pointed out in the comments, clearing the .qgis2/python/expressions/ directory solved the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.