Deltares / Ribasim

Water resources modeling
https://ribasim.org/
MIT License
42 stars 5 forks source link

Creating a new model with QGIS in the same folder errors the plugin #1679

Open deltamarnix opened 4 months ago

deltamarnix commented 4 months ago

And unfortunately, it still writes test2.toml to disk, although it does not match the database.gpkg.

An error has occurred while executing Python code:

RuntimeError: Layer Node could not be written to geopackage: C:\Users\X\ribasim_models\database.gpkg with error: Creation of data source failed (OGR error: A file system object called 'C:\Users\X\ribasim_models\database.gpkg' already exists.) Traceback (most recent call last): File "C:\Users\X\Source\Repos\Ribasim.pixi\qgis_env\profiles\default/python/plugins\ribasim_qgis\widgets\dataset_widget.py", line 261, in new_model instance.write() File "C:\Users\X\Source\Repos\Ribasim.pixi\qgis_env\profiles\default/python/plugins\ribasim_qgis\core\nodes.py", line 180, in write self.layer = geopackage.write_layer( ^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\X\Source\Repos\Ribasim.pixi\qgis_env\profiles\default/python/plugins\ribasim_qgis\core\geopackage.py", line 86, in write_layer raise RuntimeError( RuntimeError: Layer Node could not be written to geopackage: C:\Users\X\ribasim_models\database.gpkg with error: Creation of data source failed (OGR error: A file system object called 'C:\Users\X\ribasim_models\database.gpkg' already exists.)

Huite commented 4 months ago

What would the desired behavior be in this case?

There's a basic inconsistency in the fact that the TOML has a unique name, but the created geopackage does not. So I think a user may reasonably expect there not to be a problem creating a new model with a new TOML name.

You can easily overwrite content with the newfile flag, but that's guaranteed to lead to unwanted deletion of data.

Alternatively, the plugin could create the TOML with a unique name at given location, automatically create an input_directory with the same name and place the database there.

At the least though, there should be a check and a QMessageBox popping up if it can't succesfully write everything.