Bug report #11693

provider.addFeatures() returns True but fails

Added by James Novak over 9 years ago. Updated over 5 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Data Provider
Affected QGIS version:2.6.0 Regression?:No
Operating System:Windows Easy fix?:No
Pull Request or Patch supplied:No Resolution:end of life
Crashes QGIS or corrupts data:No Copied to github as #:19937

Description

With a PostGIS vector layer, providing a bad primary key produces the correct provider.hasErrors() and provider.errors() messages, but the method call returns True despite failing.

Found when developing a Python plugin.
The code involved (table has id primary key, and note varchar()):

feat = QgsFeature()
myfields = layer.dataProvider().fields()
feat.setFields(myfields)
feat.setAttribute("id", None) # The line that causes the failure. None gets translated to 0, which id already exists in table
feat.setAttribute("note", "test")
feat.setGeometry(QgsGeometry.fromPoint(point))
res = layer.dataProvider().addFeatures([feat])
# addFeature fails, but res == True !! BUG

History

#1 Updated by Jürgen Fischer over 9 years ago

Any output in the log?

#2 Updated by Jürgen Fischer over 9 years ago

  • Status changed from Open to Feedback

#3 Updated by James Novak over 9 years ago

Nothing in the QGIS Log window.

#4 Updated by Giovanni Manghi over 8 years ago

  • Status changed from Feedback to Open

#5 Updated by Giovanni Manghi about 7 years ago

  • Regression? set to No
  • Easy fix? set to No

#6 Updated by Giovanni Manghi over 5 years ago

  • Resolution set to end of life
  • Status changed from Open to Closed

Also available in: Atom PDF