Skip to content

Commit f68f288

Browse files
authoredJun 2, 2018
Merge pull request #7145 from rouault/fix_18596
[OGR provider] When editing a GeoJSON file, close and re-open the file at end of editing session (fixes #18596)
2 parents 7e2ca8f + 754018a commit f68f288

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
 

‎src/providers/ogr/qgsogrprovider.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4232,6 +4232,13 @@ bool QgsOgrProvider::leaveUpdateMode()
42324232
}
42334233
if ( !mDynamicWriteAccess )
42344234
{
4235+
// The GeoJSON driver only properly flushes stuff in all situations by
4236+
// closing and re-opening. Starting with GDAL 2.3.1, it should be safe to
4237+
// use GDALDatasetFlush().
4238+
if ( mGDALDriverName == QLatin1String( "GeoJSON" ) )
4239+
{
4240+
reloadData();
4241+
}
42354242
return true;
42364243
}
42374244
if ( mUpdateModeStackDepth == 0 )

‎tests/src/python/test_provider_ogr.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,28 @@ def testSetupProxy(self):
318318
self.assertEqual(gdal.GetConfigOption("GDAL_HTTP_PROXY"), "myproxyhostname.com")
319319
self.assertEqual(gdal.GetConfigOption("GDAL_HTTP_PROXYUSERPWD"), "username")
320320

321+
def testEditGeoJson(self):
322+
""" Test bugfix of https://issues.qgis.org/issues/18596 """
323+
324+
datasource = os.path.join(self.basetestpath, 'testEditGeoJson.json')
325+
with open(datasource, 'wt') as f:
326+
f.write("""{
327+
"type": "FeatureCollection",
328+
"features": [
329+
{ "type": "Feature", "properties": { "x": 1, "y": 2, "z": 3, "w": 4 }, "geometry": { "type": "Point", "coordinates": [ 0, 0 ] } } ] }""")
330+
331+
vl = QgsVectorLayer(datasource, 'test', 'ogr')
332+
self.assertTrue(vl.isValid())
333+
self.assertTrue(vl.startEditing())
334+
self.assertTrue(vl.deleteAttribute(1))
335+
self.assertTrue(vl.commitChanges())
336+
337+
f = QgsFeature()
338+
self.assertTrue(vl.getFeatures(QgsFeatureRequest()).nextFeature(f))
339+
self.assertEqual(f['x'], 1)
340+
self.assertEqual(f['z'], 3)
341+
self.assertEqual(f['w'], 4)
342+
321343

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

0 commit comments

Comments
 (0)
Please sign in to comment.