New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Database manager cannot import layer if any layer is None #41152
Comments
@sickel please make in the form of a pull request, thanks. |
This change will make the db managers import function more robust towards (some types of) invalid layers. cf issue qgis#41152
This change will make the db managers import function more robust towards (some types of) invalid layers. cf issue qgis#41152 Before trying to read the type of the layer when compling them for the drop down box, it checks if the layer value is of NoneType. This should not happen, but at least for some usage of the open layer plugin, a layer may end up as none type. I have observed this issue in several earlier versions of qgis and the code has not been changed since at least 3.10 LTR, so it could, and probably should be backported to 3.10
…of) invalid layers. Fix #41152
Describe the bug
Trying to use db manager to import a layer to a postgis database by pressing "Import layer/file" when a postgis database is connected, a python error is displayed and the available layers are not being listed. This happens if there is a defective layer in the project from the Open Layers plugin.
How to Reproduce
Make a connection to a postgis database, Install the open layer plugin. In a project with CRS EPSG:3857 Pseudo mercator add in e.g. Bing Roads from open layers. Save and close the project and reopen, the layer will not display. Open db manager, connect to the postgis database and press "Import layer/file". A python error will be displayed.
QGIS and OS versions
Last tested on qgis 3.16-3 on windows and linux (debian), but also seen on several previous versions.
Additional context
The bug is triggerd by a bug in open layers, but as far as I can see, the fix will not have any negative concequences and will generally make the import function more robust.
** Proposed fix **
The error message is (on my Windows 10 PC)
File "C:/PROGRA
1/QGIS31.16/apps/qgis/./python/plugins\db_manager\dlg_import_vector.py", line 135, in populateLayersif layer.type() == QgsMapLayerType.VectorLayer:
AttributeError: 'NoneType' object has no attribute 'type'
The present code is:
def populateLayers(self):
self.cboInputLayer.clear()
for nodeLayer in QgsProject.instance().layerTreeRoot().findLayers():
layer = nodeLayer.layer()
# TODO: add import raster support!
if layer.type() == QgsMapLayerType.VectorLayer:
self.cboInputLayer.addItem(layer.name(), layer.id())
this could be rewritten as:
It could of course also be done by a try / expect or a check if layer is the right type of object.
The text was updated successfully, but these errors were encountered: