mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-16 00:03:12 -04:00
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)
This commit is contained in:
commit
f68f288dea
@ -4232,6 +4232,13 @@ bool QgsOgrProvider::leaveUpdateMode()
|
||||
}
|
||||
if ( !mDynamicWriteAccess )
|
||||
{
|
||||
// The GeoJSON driver only properly flushes stuff in all situations by
|
||||
// closing and re-opening. Starting with GDAL 2.3.1, it should be safe to
|
||||
// use GDALDatasetFlush().
|
||||
if ( mGDALDriverName == QLatin1String( "GeoJSON" ) )
|
||||
{
|
||||
reloadData();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if ( mUpdateModeStackDepth == 0 )
|
||||
|
@ -318,6 +318,28 @@ class PyQgsOGRProvider(unittest.TestCase):
|
||||
self.assertEqual(gdal.GetConfigOption("GDAL_HTTP_PROXY"), "myproxyhostname.com")
|
||||
self.assertEqual(gdal.GetConfigOption("GDAL_HTTP_PROXYUSERPWD"), "username")
|
||||
|
||||
def testEditGeoJson(self):
|
||||
""" Test bugfix of https://issues.qgis.org/issues/18596 """
|
||||
|
||||
datasource = os.path.join(self.basetestpath, 'testEditGeoJson.json')
|
||||
with open(datasource, 'wt') as f:
|
||||
f.write("""{
|
||||
"type": "FeatureCollection",
|
||||
"features": [
|
||||
{ "type": "Feature", "properties": { "x": 1, "y": 2, "z": 3, "w": 4 }, "geometry": { "type": "Point", "coordinates": [ 0, 0 ] } } ] }""")
|
||||
|
||||
vl = QgsVectorLayer(datasource, 'test', 'ogr')
|
||||
self.assertTrue(vl.isValid())
|
||||
self.assertTrue(vl.startEditing())
|
||||
self.assertTrue(vl.deleteAttribute(1))
|
||||
self.assertTrue(vl.commitChanges())
|
||||
|
||||
f = QgsFeature()
|
||||
self.assertTrue(vl.getFeatures(QgsFeatureRequest()).nextFeature(f))
|
||||
self.assertEqual(f['x'], 1)
|
||||
self.assertEqual(f['z'], 3)
|
||||
self.assertEqual(f['w'], 4)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user