Bug report #18954

Crash when adding existing field to vectorlayer

Added by David Signer about 2 years ago. Updated over 1 year ago.

Status:Closed
Priority:Normal
Assignee:Peter Petrik
Category:Forms
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

Description

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...

crash-when-adding-field.gif (510 KB) David Signer, 2018-05-15 09:52 AM

Associated revisions

Revision ebcc694a
Added by Peter Petrik over 1 year ago

fix #18954 add&rename vector fields (#8982)

fix #18954 add&rename vector fields at the same time

Revision 20cd2154
Added by Peter Petrik over 1 year ago

fix #18954 add&rename vector fields (#8982) (#9042)

fix #18954 add&rename vector fields at the same time

History

#1 Updated by Peter Petrik over 1 year ago

  • Status changed from Open to In Progress
  • Assignee set to Peter Petrik

can replicate with QGIS 3.5

#2 Updated by Giovanni Manghi over 1 year ago

  • Affected QGIS version changed from 3.1(master) to 3.5(master)

#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

#4 Updated by Peter Petrik over 1 year ago

  • Pull Request or Patch supplied changed from No to Yes

#5 Updated by Peter Petrik over 1 year ago

  • % Done changed from 0 to 100
  • Status changed from In Progress to Closed

Also available in: Atom PDF