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