Bug report #18954
Crash when adding existing field to vectorlayer
|Affected QGIS version:||3.1(master)||Regression?:||No|
|Operating System:||Easy fix?:||No|
|Pull Request or Patch supplied:||Yes||Resolution:|
|Crashes QGIS or corrupts data:||Yes||Copied to github as #:||26785|
In the properties of vector layer - in the section "Source Fields" on QGIS 3 and "Fields" on QGIS 2.18.
When trying to add a feature with an existing name (unique id), a warning appears. But only if this existing name haven't been changed.
In case the name has been changed in GUI but not saved, it allows a renaming but crashes because of the still existing field-name (id).
See the GIF...
#3 Updated by Peter Petrik over 1 year ago
- Affected QGIS version changed from 3.5(master) to 3.1(master)
logic is QgsVectorLayerEditBuffer is that (QgsVectorLayerEditBuffer::updateFields and QgsVectorLayerEditBuffer::commitChanges)
1) delete attributes
2) add new attributes
3) rename all not-deleted attributes and newly added attributes in 2)
problem is when you rename "old" attribute and then add "new" attribute with the original name since QgsFields::append() in QgsVectorLayerEditBuffer::updateFields (silently) returns false.
It would be easy to fix updateField to 1) delete attributes 2) rename old 3) add new 4) rename new, but same change in commitChanges would need to change a behaviour of committedAttributesRenamed