Bug report #18954

Crash when adding existing field to vectorlayer

Added by David Signer over 6 years ago. Updated almost 6 years 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 almost 6 years ago

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

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

Revision 20cd2154
Added by Peter Petrik almost 6 years 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 almost 6 years ago

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

can replicate with QGIS 3.5

#2 Updated by Giovanni Manghi almost 6 years ago

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

#3 Updated by Peter Petrik almost 6 years 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 almost 6 years ago

  • Pull Request or Patch supplied changed from No to Yes

#5 Updated by Peter Petrik almost 6 years ago

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

Also available in: Atom PDF