[Qgis-developer] QGIS crashes when doing a rollback after modifying values of an user-added feature with pyQGIS

Manuel Hernández Martínez mhernandezm at agenciamedioambienteyagua.es
Fri Mar 4 06:05:14 PST 2016

I'm developing an add-on for QGIS that needs to assign a UUID to any feature as soon as it is added to the layer.
I'm using the featureAdded signal to write the UUID in the corresponding field of the feature.

This is the code that I am using (as simplified as possible):

    def run(self):

    def _debug_onFeatureAdded(self, fid):
        layer = self.iface.mapCanvas().currentLayer()
        layer.beginEditCommand("Set UUID")
        print layer.changeAttributeValue(fid, layer.fieldNameIndex('guid_pol'), 'some_random_uuid') # prints True

(I created a new plugin with the 'Plugin Builder' add-on and that above is the only code I have added to it.)

Unless I'm missing something, this follows the guidelines from the documentation in the QGIS developer cookbook: http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/vector.html#modifying-vector-layers-with-an-editing-buffer

When I edit the layer, if I add a feature the field 'guid_pol' is set to 'some_random_uuid' as expected. I can commit the changes without a problem, however if instead of committing the changes I try cancelling them QGIS crashes with error 0xC0000005 (Access Violation).

Interestingly, the command 'Set UUID' doesn't get added to the undo/redo stack (at least, not to the Undo/redo Panel) and if I try to undo it crashes as well.

I'm using QGIS 2.14 but I observed similar behaviour with QGIS 2.12.

I'm having a hard time getting this to work. Any help would be appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20160304/96fb7269/attachment.html>

More information about the Qgis-developer mailing list