Skip to content
Permalink
Browse files

Merge pull request #37667 from elpaso/bugfix-gh37386-filewriter-pytho…

…n-leak

Fix QgsVectorFileWriter python issue (leak & functional)
  • Loading branch information
elpaso committed Jul 8, 2020
2 parents e8c080a + 26643a6 commit 1878fc7bfd57c257abdc3cb2087741523bfa346d
@@ -431,7 +431,7 @@ Writes a layer out to a vector file.
const QgsVectorFileWriter::SaveVectorOptions &options,
QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags(),
QString *newFilename = 0,
QString *newLayer = 0 );
QString *newLayer = 0 ) /Factory/;
%Docstring
Create a new vector file writer.

@@ -635,7 +635,7 @@ class CORE_EXPORT QgsVectorFileWriter : public QgsFeatureSink
const QgsVectorFileWriter::SaveVectorOptions &options,
QgsFeatureSink::SinkFlags sinkFlags = QgsFeatureSink::SinkFlags(),
QString *newFilename = nullptr,
QString *newLayer = nullptr );
QString *newLayer = nullptr ) SIP_FACTORY;

/**
* Writes a layer out to a vector file.
@@ -29,7 +29,10 @@
QgsCoordinateTransform,
QgsMultiPolygon,
QgsTriangle,
QgsPoint
QgsPoint,
QgsFields,
QgsCoordinateTransformContext,
QgsFeatureSink
)
from qgis.PyQt.QtCore import QDate, QTime, QDateTime, QVariant, QDir, QByteArray
import os
@@ -1267,6 +1270,23 @@ def testWriteConversionErrors(self):
f = next(created_layer.getFeatures(QgsFeatureRequest()))
self.assertEqual(f['int'], 12345)

def test_regression_37386(self):
"""Test issue GH #37386"""

dest_file_name = os.path.join(str(QDir.tempPath()), 'writer_regression_37386.gpkg')
fields = QgsFields()
fields.append(QgsField("note", QVariant.Double))
lyrname = "test1"
opts = QgsVectorFileWriter.SaveVectorOptions()
opts.driverName = "GPKG"
opts.layerName = lyrname
opts.actionOnExistingFile = QgsVectorFileWriter.CreateOrOverwriteFile
writer = QgsVectorFileWriter.create(dest_file_name, fields, QgsWkbTypes.Point, QgsCoordinateReferenceSystem.fromEpsgId(4326), QgsCoordinateTransformContext(), opts, QgsFeatureSink.SinkFlags(), None, lyrname)
self.assertEqual(writer.hasError(), QgsVectorFileWriter.NoError)
del writer
vl = QgsVectorLayer(dest_file_name)
self.assertTrue(vl.isValid())


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

0 comments on commit 1878fc7

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