Le 17/12/2024 à 08:39, Alessandro Pasotti a écrit :

Can/should we fix it upstream in GDAL?

GDAL vector drivers have never really thought about the possibility of a rollback after a OGRLayer::CreateField()/AlterFieldDefn()/DeleteField(). That's a change that must be done *per driver* that supports those operations and transactions. I'd suspect the expected behaviour woud be to update the layer definition to reflect that state it had before StartTransaction(). That probably requires to have some generic logic to memorize changes and undo them, but can't probably do just a simple "clone layer definition" and restore it, because it would invalidate field definitions that aren't affected.

Ideally we'd want the following to work:

my_field_defn = layer.GetFieldDefn(0)
layer.StartTransaction()
layer.CreateField(ogr.FieldDefn("foo"))
new_field_defn = layer.GetFieldDefn("foo")
layer.RollbackTransaction()  <-- new_field_defn should be put into a "ghost" list that is destroyed at layer de-instanciation
my_field_defn.GetName() <-- hopefully that object is still alive ...
new_field_defn.GetName() <-- shouldn't crash.

Eveb


--
http://www.spatialys.com
My software is free, but my time generally not.
Butcher of all kinds of standards, open or closed formats. At the end, this is 
just about bytes.

_______________________________________________
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to