@@ -1309,10 +1309,12 @@ bool QgsOgrProvider::addAttributes( const QList<QgsField> &attributes )
1309
1309
1310
1310
bool returnvalue = true ;
1311
1311
1312
- QMap< QString, QVariant::Type > mapFieldTypesToPatch ;
1312
+ QMap< QString, QgsField > mapFieldNameToOriginalField ;
1313
1313
1314
1314
for ( QList<QgsField>::const_iterator iter = attributes.begin (); iter != attributes.end (); ++iter )
1315
1315
{
1316
+ mapFieldNameToOriginalField[ iter->name ()] = *iter;
1317
+
1316
1318
OGRFieldType type;
1317
1319
1318
1320
switch ( iter->type () )
@@ -1328,7 +1330,6 @@ bool QgsOgrProvider::addAttributes( const QList<QgsField> &attributes )
1328
1330
type = OFTInteger64;
1329
1331
else
1330
1332
{
1331
- mapFieldTypesToPatch[ iter->name ()] = iter->type ();
1332
1333
type = OFTReal;
1333
1334
}
1334
1335
break ;
@@ -1371,13 +1372,23 @@ bool QgsOgrProvider::addAttributes( const QList<QgsField> &attributes )
1371
1372
}
1372
1373
loadFields ();
1373
1374
1374
- // Patch field type in case of Integer64->Real mapping so that QVariant::LongLong
1375
- // is still returned to the caller
1376
- for ( QMap< QString, QVariant::Type >::const_iterator it = mapFieldTypesToPatch.begin (); it != mapFieldTypesToPatch.end (); ++it )
1375
+ // The check in QgsVectorLayerEditBuffer::commitChanges() is questionable with
1376
+ // real-world drivers that might only be able to satisfy request only partially.
1377
+ // So to avoid erroring out, patch field type, width and precision to match
1378
+ // what was requested.
1379
+ // For example in case of Integer64->Real mapping so that QVariant::LongLong is
1380
+ // still returned to the caller
1381
+ // Or if a field width was specified but not strictly enforced by the driver (#15614)
1382
+ for ( QMap< QString, QgsField >::const_iterator it = mapFieldNameToOriginalField.begin ();
1383
+ it != mapFieldNameToOriginalField.end (); ++it )
1377
1384
{
1378
1385
int idx = mAttributeFields .fieldNameIndex ( it.key () );
1379
1386
if ( idx >= 0 )
1380
- mAttributeFields [ idx ].setType ( *it );
1387
+ {
1388
+ mAttributeFields [ idx ].setType ( it->type () );
1389
+ mAttributeFields [ idx ].setLength ( it->length () );
1390
+ mAttributeFields [ idx ].setPrecision ( it->precision () );
1391
+ }
1381
1392
}
1382
1393
1383
1394
return returnvalue;
0 commit comments