Hi ! Thanks for your answer. I tested in more details, and it works indeed on a normal table.
But in my scenario, I am editing a view, using some triggers to make the view editable. Here's a simplified case, it consists of one table, one view, and triggers to insert/update/delete the view.: https://gist.github.com/olivierdalang/cad70df2d463d0b87566 When I insert something using this query manually : INSERT INTO test_view (name) VALUES ('abc'),('def') RETURNING id I get id > --- > 7 > 8 So it seems my triggers are working correctly (note that one mustn't forget RETURNING id INTO NEW.id in the insert trigger, without it we can't get the id back), and I was hoping that it would be transparent to QGIS. But when testing in QGIS, I get no id for the view. Here's how I test (in the python console) : def test(layerID, addedFeatures): print( 'committedFeaturesAdded was triggered on layerID'+layerID ) for feat in addedFeatures: print( 'testing id: %s' % str(feat.id()) ) print( 'testing attributes: %s' % str(feat.attributes()) ) Then this to display output when news features are commited (run this once with the normal table selected, once with the view selected) iface.activeLayer().committedFeaturesAdded.connect( test ) Then, add some features on the *table*, when you commit, you get : committedFeaturesAdded was triggered on layerIDtest20150318181848185 > testing id: 9 > testing attributes: [9, u'abc'] > testing id: 10 testing attributes: [10, u'def'] Then, add some features on the *view*, when you commit, you get : committedFeaturesAdded was triggered on layerIDtest_view20150318181847398 > testing id: 0 > testing attributes: [NULL, u'abc'] > testing id: 0 > testing attributes: [NULL, u'def'] So the ID isn't set... Am I doing something wrong ? Or is QGIS using some other way to get back the ID of a new feature ? Any idea of what that could be ? I thought updatable views were more or less transparent to QGIS, and had very good results with views up to now. Best regards, Olivier 2015-03-17 20:07 GMT+01:00 Jürgen E. <[email protected]>: > Hi Olivier, > > On Tue, 17. Mar 2015 at 18:08:18 +0100, Olivier Dalang wrote: > > I'm able to run SQL queries after inserts using this signal : > > QgsVectorLayer.committedFeaturesAdded(layerId, addedFeatures) > > > The problem is that the addedFeatures array contains the features in > their > > state BEFORE they were committed. > > Are you sure it is? I didn't try, but the postgres provider already > updates > the feature ids of the features passed to QgsPostgresProvider::addFeatures > and > and emits those in committedFeaturesAdded afterwards when the commit is > run. > > > Jürgen > > -- > Jürgen E. Fischer norBIT GmbH Tel. > +49-4931-918175-31 > Dipl.-Inf. (FH) Rheinstraße 13 Fax. > +49-4931-918175-50 > Software Engineer D-26506 Norden > http://www.norbit.de > QGIS release manager (PSC) Germany IRC: jef on FreeNode > > _______________________________________________ > Qgis-developer mailing list > [email protected] > http://lists.osgeo.org/mailman/listinfo/qgis-developer >
_______________________________________________ Qgis-developer mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/qgis-developer
