Skip to content
Permalink
Browse files

Merge pull request #36677 from elpaso/bugfix-36525-auto-transactions

Fix transaction groups on multiple GPKGs
  • Loading branch information
elpaso committed May 23, 2020
2 parents 42ba3d7 + c343af7 commit f13b739903faa6ce10b0f11c801a8d1ba52ccf32
Showing with 43 additions and 2 deletions.
  1. +2 −2 src/core/qgsproject.cpp
  2. +41 −0 tests/src/python/test_provider_ogr_gpkg.py
@@ -1880,8 +1880,8 @@ void QgsProject::onMapLayersAdded( const QList<QgsMapLayer *> &layers )
{
if ( QgsTransaction::supportsTransaction( vlayer ) )
{
QString connString = QgsDataSourceUri( vlayer->source() ).connectionInfo();
QString key = vlayer->providerType();
const QString connString = QgsTransaction::connectionString( vlayer->source() );
const QString key = vlayer->providerType();

QgsTransactionGroup *tg = mTransactionGroups.value( qMakePair( key, connString ) );

@@ -1578,6 +1578,47 @@ def testExporterWithFIDColumn(self):
self.assertEqual(f.attributes(), [123, 'text1'])
self.assertEqual(f.id(), 123)

def testTransactionGroup(self):
"""Issue https://github.com/qgis/QGIS/issues/36525"""

project = QgsProject()
project.setAutoTransaction(True)
tmpfile1 = os.path.join(self.basetestpath, 'tempGeoPackageTransactionGroup1.gpkg')
tmpfile2 = os.path.join(self.basetestpath, 'tempGeoPackageTransactionGroup2.gpkg')
for tmpfile in (tmpfile1, tmpfile2):
ds = ogr.GetDriverByName('GPKG').CreateDataSource(tmpfile)
for i in range(2):
lyr = ds.CreateLayer('test%s' % i, geom_type=ogr.wkbPoint)
lyr.CreateField(ogr.FieldDefn('str_field', ogr.OFTString))
f = ogr.Feature(lyr.GetLayerDefn())
f.SetGeometry(ogr.CreateGeometryFromWkt('POINT (1 1)'))
f.SetField('str_field', 'one')
lyr.CreateFeature(f)

vl1_1 = QgsVectorLayer(tmpfile1, 'test1_1', 'ogr')
self.assertTrue(vl1_1.isValid())
vl1_2 = QgsVectorLayer(tmpfile1, 'test1_2', 'ogr')
self.assertTrue(vl1_2.isValid())
vl2_1 = QgsVectorLayer(tmpfile2, 'test2_1', 'ogr')
self.assertTrue(vl2_1.isValid())
vl2_2 = QgsVectorLayer(tmpfile2, 'test2_2', 'ogr')
self.assertTrue(vl2_2.isValid())
project.addMapLayers([vl1_1, vl1_2, vl2_1, vl2_2])

self.assertTrue(vl1_1.startEditing())
self.assertTrue(vl1_2.isEditable())
self.assertFalse(vl2_1.isEditable())
self.assertFalse(vl2_2.isEditable())

self.assertTrue(vl1_1.rollBack())
self.assertFalse(vl1_1.isEditable())
self.assertFalse(vl1_2.isEditable())

self.assertTrue(vl2_1.startEditing())
self.assertTrue(vl2_2.isEditable())
self.assertFalse(vl1_1.isEditable())
self.assertFalse(vl1_2.isEditable())


if __name__ == '__main__':
unittest.main()

0 comments on commit f13b739

Please sign in to comment.
You can’t perform that action at this time.