from qgis.core import * from qgis.gui import * from qgis.utils import * """ fun1() works. All features are selected. Usage: fun1(1) """ @qgsfunction(args='auto', group='Custom') def fun1(value1, feature, parent): return value1 """ fun2() works. All features are selected. Usage: fun2(2) """ @qgsfunction(args='auto', group='Custom') def fun2(value1, feature, parent): return value1 + 45 """ No features are selected on executing fun3(). Usage: fun3() """ @qgsfunction(args=0, group='Custom') def fun3(value1, feature, parent): if feature['osm_id']: return True else: return False """ fun4() is a workaround I tried to select features. It is slow and not a good solution to the problem. Usage: fun4() """ @qgsfunction(args=0, group='Custom') def fun4(value1, feature, parent): layer=iface.activeLayer() iter=layer.getFeatures() for feature in iter: return feature['osm_id']