0

Using QGIS 3.16 I have several Geopackages already, which I would like to import a file into and make a new layer. I'm using the DB Manager > Table > Import Layer/File menu item. QGIS throws a traceback.

021-12-20T11:02:55     WARNING    Traceback (most recent call last):
          File "D:/Program Files/QGIS 3.16/apps/qgis/./python/plugins\db_manager\db_manager.py", line 169, in importActionSlot
          dlg = DlgImportVector(None, db, outUri, self)
          File "D:/Program Files/QGIS 3.16/apps/qgis/./python/plugins\db_manager\dlg_import_vector.py", line 69, in __init__
          self.populateLayers()
          File "D:/Program Files/QGIS 3.16/apps/qgis/./python/plugins\db_manager\dlg_import_vector.py", line 135, in populateLayers
          if layer.type() == QgsMapLayerType.VectorLayer:
         AttributeError: 'NoneType' object has no attribute 'type'

This happens on all the databases. Tried to close project down and restart. no dice.

Anyone have a clue as to what I should be looking for?

1 Answer 1

0

ok bit of a weird one, I managed to work it out by debugging the code itself in the dlg_import_vector.py file.

I ran the following in the python console inside my project, which was similar to the method call in the project.

for nodeLayer in QgsProject.instance().layerTreeRoot().findLayers():
print(nodeLayer.layer(), " ", nodeLayer.layer().type)

This gave me the list of layers, and then the layer that causes the error.

Upon inspection, there was a layer in my layer list, in the project, that I could not perform any actions on using right mouse click, other than remove/copy/move in group etc. All the zoom to, properties, style, filter etc menu options were not listed.

It's like the layer was corrupted somewhat. No idea how, it didn't appear to be a pathing issue.

Anyways - the root cause of the problem was that there was a layer in my layer list which was corrupted and by using the above code, I was able to find out which layer it was. The corruption then causes the object.type to equal null, which then causes the traceback.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.