<div dir="ltr"><div>Thank you Nyall!</div><div><br></div><div>That solved the problem. I failed to see that in the C++ code for split features tool, but it was there.<br></div><div><br></div><div>The only small annoyance that I had was the need to convert the result of feature.attributes() into a dictionary.</div><div><br></div><div><br></div><div>Once again, thanks! It solved a long-standing issue in the plugin.</div><div><br></div><div>Alex<br></div><div><br></div><div>But it for the clarification.<span> </span></div><div class="gmail_quote"><div dir="ltr">A qua, 28/03/2018, 23:01, Nyall Dawson <<a href="mailto:nyall.dawson@gmail.com" target="_blank">nyall.dawson@gmail.com</a>> escreveu:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 28 March 2018 at 08:32, Alexandre Neto <<a href="mailto:senhor.neto@gmail.com" target="_blank">senhor.neto@gmail.com</a>> wrote:<br>
> My multipart split plugin (which I am porting to 3), It breaks multipart<br>
> features and transforms each part in individual features, copying the<br>
> attributes from the original feature.<br>
><br>
> In the process, I need to be careful with the autoincrement primary keys.<br>
> For PostGIS and Spatialite, asking for the providers pkattributesindex works<br>
> and I can do the following:<br>
><br>
> new_attributes = feature.attributes()<br>
><br>
> # When attribute is a Primary Key, replace by default value<br>
> ### This is not working well with spatialite provider###<br>
> for j in provider.pkAttributeIndexes():<br>
>     if provider.defaultValue(j):<br>
>         new_attributes[j] = provider.defaultValue(j)<br>
>     else:<br>
>         new_attributes[j] = QVariant()<br>
><br>
> But for geopackage the provider.pkAttributeIndexes() always returns an empty<br>
> list...<br>
><br>
> The above code was copied a long time ago from the split features tools in<br>
> core. Looking at the code now, there is no longer that part where the<br>
> provider's primary keys are searched, Nevertheless, the code works and the<br>
> split features tool leave the pkattributes NULL to be autogenerated. Wasn't<br>
> able to figure out where that is done now ...<br>
<br>
The canonical/correct 3.0 way to do this is to use<br>
QgsVectorLayerUtils.createFeature<br>
<br>
That method should be used whenever you are creating a brand new<br>
feature which is destined for a particular vector layer, and needs to<br>
correctly respect constraints and default value clauses set on the<br>
provider side.<br>
<br>
Nyall<br>
</blockquote></div></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Alexandre Neto</div><div>---------------------</div><div>@AlexNetoGeo</div><div><a href="http://sigsemgrilhetas.wordpress.com">http://sigsemgrilhetas.wordpress.com</a></div><a href="http://gisunchained.wordpress.com">http://gisunchained.wordpress.com</a><br></div></div>