From 6bf931263f5a12ed32a3f4ca808b4c8c9b7125db Mon Sep 17 00:00:00 2001 From: Martijn Visser Date: Thu, 14 Mar 2024 17:03:16 +0100 Subject: [PATCH] QGIS: don't crash on unknown layers in database (#1265) Currently both Ribasim Python and the core silently ignore extra unknown tables. This makes QGIS do the same. ``` An error has occurred while executing Python code: KeyError: 'Basin / boundaryconcentration' Traceback (most recent call last): File "C:\Users/visser_mn/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ribasim_qgis\widgets\dataset_widget.py", line 286, in open_model self.load_geopackage() File "C:\Users/visser_mn/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ribasim_qgis\widgets\dataset_widget.py", line 221, in load_geopackage nodes = load_nodes_from_geopackage(geo_path) File "C:\Users/visser_mn/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ribasim_qgis\core\nodes.py", line 870, in load_nodes_from_geopackage nodes[layername] = NODES[layername](path) KeyError: 'Basin / boundaryconcentration' ``` --------- Co-authored-by: Maarten Pronk <8655030+evetion@users.noreply.github.com> --- ribasim_qgis/core/nodes.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ribasim_qgis/core/nodes.py b/ribasim_qgis/core/nodes.py index c65022c59..a27c775f5 100644 --- a/ribasim_qgis/core/nodes.py +++ b/ribasim_qgis/core/nodes.py @@ -867,5 +867,7 @@ def load_nodes_from_geopackage(path: Path) -> dict[str, Input]: gpkg_names = geopackage.layers(path) nodes = {} for layername in gpkg_names: - nodes[layername] = NODES[layername](path) + klass = NODES.get(layername) + if klass is not None: + nodes[layername] = klass(path) return nodes