Open louis2607 opened 1 year ago
See: #3597.
The flags could have been made a lot more understandable by changing them to something like:
SaveVectorOptions.behavior = QgsVectorFileWriter.CreateOrOverwriteFile and SaveVectorOptions.behavior = QgsVectorFileWriter.CreateOrOverwriteLayerInFile
But even then, I am not sure I personally agree with forcing trying to open the file in update mode with CreateOrOverwriteLayer even if there is no file. This seems illogical when you set a flag on what you expect to happen when there is an existing file and shouldn't have an impact when there is not one.
What is the bug or the crash?
Setting
actionOnExistingFile
parameter ofQgsVectorFileWriter.SaveVectorOptions
toQgsVectorFileWriter.CreateOrOverwriteLayer
also changes behavior when the file doesn't exist.Saving to an empty location with that save options result in the function
writeAsVectorFormatV3
returning a code 2 error which is 'Opening of data source in update mode failed (OGR error: )'.However based on the name of the save option, this is not the behavior one would expect.
At least in my opinion the expected behavior would be that this save option parameter gets ignored if the file doesn't exists.
Steps to reproduce the issue
save location
geopackage = '/path/to/geopackage.gpkg' # PATH WITH NO EXISTING FILE
write the layer to disk
options = QgsVectorFileWriter.SaveVectorOptions() options.actionOnExistingFile = QgsVectorFileWriter.CreateOrOverwriteLayer options.layerName = layer.name() result = QgsVectorFileWriter.writeAsVectorFormatV3(layer, geopackage, QgsCoordinateTransformContext(), options) print(result)