Bug report #12281
Incorrect feature Id in a shapefile layer
|Affected QGIS version:||master||Regression?:||No|
|Operating System:||Easy fix?:||No|
|Pull Request or Patch supplied:||No||Resolution:||end of life|
|Crashes QGIS or corrupts data:||No||Copied to github as #:||20463|
We have been working with the form init function of a layer and the signal featureAdded(QgsFeatureId) trying to capture the different steps a feature passes before being inserted in a layer. I have started working with a Shapefile layer.
We have prepared a init function for the layer (Python Init Function) that is called before the form is opened, I have also captured the signal when a feature is added to a layer.
In each of these functions I have print the feature id of the element being inserted. The shapefile is empty when I start the test.
According to the debug traces In the first step before the form is opened the feature id of the new feature is always "0". In the second step when I closed the form and the featureAdd signal is called I receive a negative number (-1,-2,...). When I commit the changes I have also received associated with the featureAdded signal a new Id. In the last step is "0" because is the first feature.
In successive tests the behaviour was the same but in the last step the second feature received "1" and so on.
We have test the same behaviour with a spatialite layer and a postgis layer and the behaviour is similar but when the feature is commited in both cases it starts in "1" instead in "0". I think this is the correct behaviour because in the shapefile test is impossible to know in the first step if the feature being inserted is new or not because the formOpened method is called with a new feature or when you identify a feature in the layer.
In order to know if the feature is new or not, we try to search the "0" feature in the layer and we always get one. We don't know if there is another way to check that but with spatialite and postgis this methos works.
I have also tested with the master version and the results is the same.
#3 Updated by Giovanni Manghi over 1 year ago
- Resolution set to end of life
- Status changed from Open to Closed
End of life notice: QGIS 2.18 LTR