Bug report #13032
Save as... fails to populate fields if layer has similar names only different by case
|Affected QGIS version:||master||Regression?:||No|
|Operating System:||Easy fix?:||No|
|Pull Request or Patch supplied:||No||Resolution:|
|Crashes QGIS or corrupts data:||Yes||Copied to github as #:||21107|
When using "save as..." in a layer, the tool fails to fill all fields values correctly if there are columns with similar names (being CAPS the only difference; I know it's a bad policy to give similar names to columns, but... it's out of my reach)
QGIS will consider that the columns have the same name, and therefore will create a new column with a suffix (fieldname_1). So far so good. But then fails to populate the new column with values.
I have marked that it causes corruption since the output will not be what the user expects.
I believe that issue #13027 is also related. Have something to do with the QgsVectorFileWriter.
To replicate the problem one can create a memory layer and add two columns named 'fieldname' and 'FieldName', and add some features. Notice that the feature form won't work well and will fill both fields at the same time. Edit them in the attribute table. Save. Use Save as... to make the layer permanent.
- fieldNameIndex: resort to case-insensitive lookup only if
case-sensitive lookup has no match
- file writer: fix handling of fields that only differ by case