osmcode / pyosmium

Python bindings for libosmium
https://osmcode.org/pyosmium
BSD 2-Clause "Simplified" License
318 stars 65 forks source link

SimpleWriter.add_node can write invalid nodes on error #212

Closed morandd closed 2 years ago

morandd commented 2 years ago

Hard to replicate this, but it seems that if SimpleWriter.add_node fails due to a Python->C++ typecasting error, it will still write an invalid node to the output. The output files seem to contain multiple nodes with id=0 and no tags at the same lines where I encounter casting errors.

so:

try 
    writer.add_node(oo)
catch
# error message like this:
RuntimeError: Unable to cast Python instance to C++ type (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)
{'GgCO2': '0.6217761361811466', 't': 'other', 'addr:constituency': 'Madevu', 'addr:ward': 'Mtendere Ward 30', 'amenity': 'waste_disposal'}

seems to write an incomplete node to the output file.

This is problematic because the incomplete node has ID=0, and if there are multiple cases this introduces duplicate nodes with id=0.

Hopefully this is an easy fix to simply not write anything to the file in case of an error during the Python->C++ typecasting for tags?