Deltares / Ribasim

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

Error when adding the same table twice in QGIS #1685

Open deltamarnix opened 1 month ago

deltamarnix commented 1 month ago

An error has occurred while executing Python code:

ValueError: Name already exists in geopackage: Basin / time Traceback (most recent call last): File "C:\Users\X\Source\Repos\Ribasim.pixi\qgis_env\profiles\default/python/plugins\ribasim_qgis\widgets\nodes_widget.py", line 61, in new_node_layer node = klass.create( ^^^^^^^^^^^^^ File "C:\Users\X\Source\Repos\Ribasim.pixi\qgis_env\profiles\default/python/plugins\ribasim_qgis\core\nodes.py", line 86, in create raise ValueError(f"Name already exists in geopackage: {cls.input_type()}") ValueError: Name already exists in geopackage: Basin / time

Expected: The button gets disabled once a layer with that name was there.

Huite commented 1 month ago

Disabling is one option, but it's difficult to implement. I would raise an error here and show a QMessageBox instead.

The reason that it's difficult to implement is because there's all kinds of ways in which people may delete the layer from the underlying geopackage. Through the "Remove from Dataset" button is one, but another is through the Browser Panel. Another is running an SQLite query through QGIS's processing toolbox, or maybe via a script in the background. This means you cannot rely on the Qt signals to inform you that the button should be re-enabled (granted, >99% of deletion would occur through "Remove from Dataset").

What easier to implement is prior to creating the layer, check the layers in the geopackage. Then error message if the name already exists. To be fair this check already occurs and you could just try-except this specific ValueError and just show this error in a QMessageBox.