Skip to content

Commit

Permalink
Merge pull request #37667 from elpaso/bugfix-gh37386-filewriter-pytho…
Browse files Browse the repository at this point in the history
…n-leak

Fix QgsVectorFileWriter python issue (leak & functional)
  • Loading branch information
elpaso committed Jul 8, 2020
2 parents e8c080a + 26643a6 commit 1878fc7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion python/core/auto_generated/qgsvectorfilewriter.sip.in
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorfilewriter.h
Expand Up @@ -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.
Expand Down
22 changes: 21 additions & 1 deletion tests/src/python/test_qgsvectorfilewriter.py
Expand Up @@ -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
Expand Down Expand Up @@ -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.