@@ -1578,6 +1578,47 @@ def testExporterWithFIDColumn(self):
1578
1578
self .assertEqual (f .attributes (), [123 , 'text1' ])
1579
1579
self .assertEqual (f .id (), 123 )
1580
1580
1581
+ def testTransactionGroup (self ):
1582
+ """Issue https://github.com/qgis/QGIS/issues/36525"""
1583
+
1584
+ project = QgsProject ()
1585
+ project .setAutoTransaction (True )
1586
+ tmpfile1 = os .path .join (self .basetestpath , 'tempGeoPackageTransactionGroup1.gpkg' )
1587
+ tmpfile2 = os .path .join (self .basetestpath , 'tempGeoPackageTransactionGroup2.gpkg' )
1588
+ for tmpfile in (tmpfile1 , tmpfile2 ):
1589
+ ds = ogr .GetDriverByName ('GPKG' ).CreateDataSource (tmpfile )
1590
+ for i in range (2 ):
1591
+ lyr = ds .CreateLayer ('test%s' % i , geom_type = ogr .wkbPoint )
1592
+ lyr .CreateField (ogr .FieldDefn ('str_field' , ogr .OFTString ))
1593
+ f = ogr .Feature (lyr .GetLayerDefn ())
1594
+ f .SetGeometry (ogr .CreateGeometryFromWkt ('POINT (1 1)' ))
1595
+ f .SetField ('str_field' , 'one' )
1596
+ lyr .CreateFeature (f )
1597
+
1598
+ vl1_1 = QgsVectorLayer (tmpfile1 , 'test1_1' , 'ogr' )
1599
+ self .assertTrue (vl1_1 .isValid ())
1600
+ vl1_2 = QgsVectorLayer (tmpfile1 , 'test1_2' , 'ogr' )
1601
+ self .assertTrue (vl1_2 .isValid ())
1602
+ vl2_1 = QgsVectorLayer (tmpfile2 , 'test2_1' , 'ogr' )
1603
+ self .assertTrue (vl2_1 .isValid ())
1604
+ vl2_2 = QgsVectorLayer (tmpfile2 , 'test2_2' , 'ogr' )
1605
+ self .assertTrue (vl2_2 .isValid ())
1606
+ project .addMapLayers ([vl1_1 , vl1_2 , vl2_1 , vl2_2 ])
1607
+
1608
+ self .assertTrue (vl1_1 .startEditing ())
1609
+ self .assertTrue (vl1_2 .isEditable ())
1610
+ self .assertFalse (vl2_1 .isEditable ())
1611
+ self .assertFalse (vl2_2 .isEditable ())
1612
+
1613
+ self .assertTrue (vl1_1 .rollBack ())
1614
+ self .assertFalse (vl1_1 .isEditable ())
1615
+ self .assertFalse (vl1_2 .isEditable ())
1616
+
1617
+ self .assertTrue (vl2_1 .startEditing ())
1618
+ self .assertTrue (vl2_2 .isEditable ())
1619
+ self .assertFalse (vl1_1 .isEditable ())
1620
+ self .assertFalse (vl1_2 .isEditable ())
1621
+
1581
1622
1582
1623
if __name__ == '__main__' :
1583
1624
unittest .main ()
0 commit comments