<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EstiloCorreo17
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.EstiloCorreo18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 3.0cm 70.85pt 3.0cm;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=ES link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span lang=EN-GB>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.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB>I'm using the featureAdded signal to write the UUID in the corresponding field of the feature.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB>This is the code that I am using (as simplified as possible):<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB>    def run(self):<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB>        self.iface.mapCanvas().currentLayer().featureAdded.connect(self._debug_onFeatureAdded)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB>       <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB>    def _debug_onFeatureAdded(self, fid):<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB>        layer = self.iface.mapCanvas().currentLayer()<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB>        layer.beginEditCommand("Set UUID")<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB>        print layer.changeAttributeValue(fid, layer.fieldNameIndex('guid_pol'), 'some_random_uuid') # prints True<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB>        layer.endEditCommand()<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB>(I created a new plugin with the 'Plugin Builder' add-on and that above is the only code I have added to it.)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB>Unless I'm missing something, this follows the guidelines from the documentation in the QGIS developer cookbook: <a href="http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/vector.html#modifying-vector-layers-with-an-editing-buffer">http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/vector.html#modifying-vector-layers-with-an-editing-buffer</a><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB>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).<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB>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.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB>I'm using QGIS 2.14 but I observed similar behaviour with QGIS 2.12.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB>I'm having a hard time getting this to work. Any help would be appreciated.<o:p></o:p></span></p></div></body></html>