|
33 | 33 | QgsReadWriteContext,
|
34 | 34 | QgsRectangle,
|
35 | 35 | QgsDefaultValue,
|
36 |
| - QgsDataSourceUri |
| 36 | + QgsDataSourceUri, |
| 37 | + QgsProject |
37 | 38 | )
|
38 | 39 | from qgis.gui import QgsGui
|
39 | 40 | from qgis.PyQt.QtCore import QDate, QTime, QDateTime, QVariant, QDir, QObject
|
@@ -312,6 +313,54 @@ def testNestedInsert(self):
|
312 | 313 | self.vl.addFeature(f) # Should not deadlock during an active iteration
|
313 | 314 | f = next(it)
|
314 | 315 |
|
| 316 | + def testTransactionNotDirty(self): |
| 317 | + # create a vector ayer based on postgres |
| 318 | + vl = QgsVectorLayer(self.dbconn + ' sslmode=disable key=\'pk\' srid=4326 type=POLYGON table="qgis_test"."some_poly_data" (geom) sql=', 'test', 'postgres') |
| 319 | + self.assertTrue(vl.isValid()) |
| 320 | + |
| 321 | + # prepare a project with transactions enabled |
| 322 | + p = QgsProject() |
| 323 | + p.setAutoTransaction(True) |
| 324 | + p.addMapLayers([vl]) |
| 325 | + vl.startEditing() |
| 326 | + |
| 327 | + # check that the feature used for testing is ok |
| 328 | + ft0 = vl.getFeatures('pk=1') |
| 329 | + f = QgsFeature() |
| 330 | + self.assertTrue(ft0.nextFeature(f)) |
| 331 | + |
| 332 | + # update the data within the transaction |
| 333 | + tr = vl.dataProvider().transaction() |
| 334 | + sql = "update qgis_test.some_poly_data set pk=33 where pk=1" |
| 335 | + self.assertTrue(tr.executeSql(sql, True)[0]) |
| 336 | + |
| 337 | + # check that the pk of the feature has been changed |
| 338 | + ft = vl.getFeatures('pk=1') |
| 339 | + self.assertFalse(ft.nextFeature(f)) |
| 340 | + |
| 341 | + ft = vl.getFeatures('pk=33') |
| 342 | + self.assertTrue(ft.nextFeature(f)) |
| 343 | + |
| 344 | + # underlying data has been modified but the layer is not tagged as |
| 345 | + # modified |
| 346 | + self.assertTrue(vl.isModified()) |
| 347 | + |
| 348 | + # undo sql query |
| 349 | + vl.undoStack().undo() |
| 350 | + |
| 351 | + # check that the original feature with pk is back |
| 352 | + ft0 = vl.getFeatures('pk=1') |
| 353 | + self.assertTrue(ft0.nextFeature(f)) |
| 354 | + |
| 355 | + # redo |
| 356 | + vl.undoStack().redo() |
| 357 | + |
| 358 | + # check that the pk of the feature has been changed |
| 359 | + ft1 = vl.getFeatures('pk=1') |
| 360 | + self.assertFalse(ft1.nextFeature(f)) |
| 361 | + |
| 362 | + p.setAutoTransaction(False) |
| 363 | + |
315 | 364 | def testDomainTypes(self):
|
316 | 365 | """Test that domain types are correctly mapped"""
|
317 | 366 |
|
|
0 commit comments