Skip to content
Browse files
Add provider test to ensure that adding features to a provider
with MORE attributes than expected results in a failure

We need to flag these and not silently discard the extra
attributes resulting in loss of information -- if thisi
situation occurs there's a deeper bug present whic
 needs to be addressed.
  • Loading branch information
nyalldawson committed Feb 17, 2018
1 parent 17039ff commit 4ae476da998b3e78289072edd99648ff7abd5394
Showing with 24 additions and 0 deletions.
  1. +24 −0 tests/src/python/
@@ -467,6 +467,30 @@ def testAddFeatureMissingAttributes(self):
f2.setAttributes([7, 330, NULL, NULL, 'NULL'])
self.testGetFeatures(l.dataProvider(), [f1, f2])

def testAddFeatureExtraAttributes(self):
if not getattr(self, 'getEditableLayer', None):

l = self.getEditableLayer()

if not l.dataProvider().capabilities() & QgsVectorDataProvider.AddFeatures:

# test that adding features with too many attributes rejects the feature
# we be more tricky and also add a valid feature to stress test the provider
f1 = QgsFeature()
f1.setAttributes([6, -220, NULL, 'String', '15'])
f2 = QgsFeature()
f1.setAttributes([7, -230, NULL, 'String', '15', 15, 16, 17])

result, added = l.dataProvider().addFeatures([f1, f2])
self.assertFalse(result, 'Provider returned True to addFeatures with extra attributes. Providers should reject these features.')

# make sure feature was not added
added = [f for f in l.dataProvider().getFeatures() if f['pk'] == 7]

def testAddFeaturesUpdateExtent(self):
if not getattr(self, 'getEditableLayer', None):

0 comments on commit 4ae476d

Please sign in to comment.