geopandas / pyogrio

Vectorized vector I/O using OGR
https://pyogrio.readthedocs.io
MIT License
257 stars 21 forks source link

Need to call GDALClose when writing fails? #394

Closed jorisvandenbossche closed 2 months ago

jorisvandenbossche commented 2 months ago

Currently in the writing code (eg ogr_write) we have a final cleanup block where we close the dataset (and check for errors, which was corrected in https://github.com/geopandas/pyogrio/pull/284):

https://github.com/geopandas/pyogrio/blob/154466ab555f395d24b3d4873e685a841dd81fa6/pyogrio/_io.pyx#L2277-L2295

But when an error happens while writing (and this is already bubbled up), we don't close the dataset, see the finally: block in the snippet above (we only clean up the current Feature variable).

When I compare that with the various read paths, it seems we always close the dataset in the finally block, eg in ogr_read:

https://github.com/geopandas/pyogrio/blob/154466ab555f395d24b3d4873e685a841dd81fa6/pyogrio/_io.pyx#L1245-L1255