@@ -1342,10 +1342,12 @@ bool QgsOgrProvider::addAttributes( const QList<QgsField> &attributes )
1342
1342
1343
1343
bool returnvalue = true ;
1344
1344
1345
- QMap< QString, QVariant::Type > mapFieldTypesToPatch ;
1345
+ QMap< QString, QgsField > mapFieldNameToOriginalField ;
1346
1346
1347
1347
for ( QList<QgsField>::const_iterator iter = attributes.begin (); iter != attributes.end (); ++iter )
1348
1348
{
1349
+ mapFieldNameToOriginalField[ iter->name ()] = *iter;
1350
+
1349
1351
OGRFieldType type;
1350
1352
1351
1353
switch ( iter->type () )
@@ -1361,7 +1363,6 @@ bool QgsOgrProvider::addAttributes( const QList<QgsField> &attributes )
1361
1363
type = OFTInteger64;
1362
1364
else
1363
1365
{
1364
- mapFieldTypesToPatch[ iter->name ()] = iter->type ();
1365
1366
type = OFTReal;
1366
1367
}
1367
1368
break ;
@@ -1404,13 +1405,23 @@ bool QgsOgrProvider::addAttributes( const QList<QgsField> &attributes )
1404
1405
}
1405
1406
loadFields ();
1406
1407
1407
- // Patch field type in case of Integer64->Real mapping so that QVariant::LongLong
1408
- // is still returned to the caller
1409
- for ( QMap< QString, QVariant::Type >::const_iterator it = mapFieldTypesToPatch.begin (); it != mapFieldTypesToPatch.end (); ++it )
1408
+ // The check in QgsVectorLayerEditBuffer::commitChanges() is questionable with
1409
+ // real-world drivers that might only be able to satisfy request only partially.
1410
+ // So to avoid erroring out, patch field type, width and precision to match
1411
+ // what was requested.
1412
+ // For example in case of Integer64->Real mapping so that QVariant::LongLong is
1413
+ // still returned to the caller
1414
+ // Or if a field width was specified but not strictly enforced by the driver (#15614)
1415
+ for ( QMap< QString, QgsField >::const_iterator it = mapFieldNameToOriginalField.begin ();
1416
+ it != mapFieldNameToOriginalField.end (); ++it )
1410
1417
{
1411
1418
int idx = mAttributeFields .fieldNameIndex ( it.key () );
1412
1419
if ( idx >= 0 )
1413
- mAttributeFields [ idx ].setType ( *it );
1420
+ {
1421
+ mAttributeFields [ idx ].setType ( it->type () );
1422
+ mAttributeFields [ idx ].setLength ( it->length () );
1423
+ mAttributeFields [ idx ].setPrecision ( it->precision () );
1424
+ }
1414
1425
}
1415
1426
1416
1427
return returnvalue;
0 commit comments