GeoNode / QGISGeoNodePlugin

A QGIS plugin that provides integration with GeoNode
https://geonode.org/QGISGeoNodePlugin/
GNU General Public License v3.0
12 stars 16 forks source link

Error when trying to reload a default style or metadata from GeoNode #285

Open Gpetrak opened 3 weeks ago

Gpetrak commented 3 weeks ago

Although the style upload in GeoNode works, when the user tries to get the default style by selecting the button: “Reload the default style from GeoNode” the plugin raises the following error:

Traceback (most recent call last):
  File "/home/gpetr/.local/share/QGIS/QGIS3/profiles/test/python/plugins/qgis_geonode/gui/geonode_map_layer_config_widget.py", line 171, in handle_style_downloaded
    self.apply()
  File "/home/gpetr/.local/share/QGIS/QGIS3/profiles/test/python/plugins/qgis_geonode/gui/geonode_map_layer_config_widget.py", line 127, in apply
    self._apply_sld()
  File "/home/gpetr/.local/share/QGIS/QGIS3/profiles/test/python/plugins/qgis_geonode/gui/geonode_map_layer_config_widget.py", line 437, in _apply_sld
    layer_properties_dialog.syncToLayer()
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'QFrame' object has no attribute 'syncToLayer'

Also, when the user tries to reload metadata by selecting the button: “Reload metadata from GeoNode” it gets a quite similar error:

Traceback (most recent call last):
  File "/home/gpetr/.local/share/QGIS/QGIS3/profiles/test/python/plugins/qgis_geonode/gui/geonode_map_layer_config_widget.py", line 311, in handle_metadata_downloaded
    self.apply()
  File "/home/gpetr/.local/share/QGIS/QGIS3/profiles/test/python/plugins/qgis_geonode/gui/geonode_map_layer_config_widget.py", line 127, in apply
    self._apply_sld()
  File "/home/gpetr/.local/share/QGIS/QGIS3/profiles/test/python/plugins/qgis_geonode/gui/geonode_map_layer_config_widget.py", line 432, in _apply_sld
    sld_load_result = self.layer.readSld(
                      ^^^^^^^^^^^^^^^^^^^
TypeError: readSld(self, node: QDomNode, errorMessage: str): argument 1 has unexpected type 'NoneType'
giohappy commented 2 weeks ago

does it happen always or erratically @Gpetrak?

Gpetrak commented 2 weeks ago

@giohappy this happens always.

giohappy commented 2 weeks ago

@Gpetrak I suspect the first problem is related to this hacky code:

https://github.com/GeoNode/QGISGeoNodePlugin/blob/6eed6e3d1a1e066657997767c242d052530f985c/src/qgis_geonode/gui/geonode_map_layer_config_widget.py#L452-L455

Maybe this traversal doesn't work for other reasons here (an error stream with the style retrieval, or whatever). In any case this solution is very fragile. If a better way is not available, and a traversal is the only solution, a more robust traversal should be implemented. It could be an iterative loop where the type of the parent class is checked to obtain the one we're looking for.

Gpetrak commented 1 week ago

Thank you @giohappy. Finally, I fixed the error of SLD and Metadata and I implemented a more elegant way in order to find the correct type of object, following your recommendation. The corresponding PR of this issue is available here #294