Bug report #12938

DB Manager adds invisible layers to TOC during layer preview and doesn't remove them after it is closed

Added by Yury Ryabov over 8 years ago. Updated over 8 years ago.

Assignee:Giuseppe Sucameli
Category:DB Manager
Affected QGIS version:2.8.2 Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:21018


Open DB Manager, connect to the PostgGIS database (haven't testet on Spatialite), select table that have geometry column and click on preview tab. DB Manager shows the preview of the vector layer and at the same time this layer is silently added to current QGIS TOC. This layer doesn't appear in TOC for user, but is retrieved if TOC content is queryed using Python. If user selects another table with geometry column and preview it DB Manager, new table will be added to TOC the same way and the first one will remain. Both table names will remain (unseen to user) in TOC even after the DB Manager is closed. On closing DB Manager the exeption runtime error is raised, see log:

>>>def laylist():
>>>  l=[]
>>>  for layer in QgsMapLayerRegistry.instance().mapLayers().values():
>>>    item = layer.name()
>>>    l.append(item)
>>>  print l
# There is only one layer 'buf' (a shp-file) in QGIS TOC. Check the TOC
# Now open DM Manager, connect to the PostGIS DB and preview one of the spatially enabled tables ('park_kvartal3_utm') without adding them to TOC
# Check TOC again:
[u'park_kvartal3_utm', u'buf']
# Now in DB Manager select another spatial table ('itog_region_utm') and preview it without adding it to TOC
[u'park_kvartal3_utm', u'itog_region_utm', u'buf']
# Close DB Manager and catch exception. 
Exception RuntimeError: 'wrapped C/C++ object of type PGVectorTable has been deleted' in <bound method PGTableDataModel.__del__ of <db_manager.db_plugins.postgis.data_model.PGTableDataModel object at 0x7f17550dedf8>> ignored
# Check TOC content again after the DB Manager is closed. Notice: no layer was added to TOC by user during DB Manager session. The names of table remains:
[u'park_kvartal3_utm', u'itog_region_utm', u'buf']

Ideally these names shouldn't be added to TOC at all.

Associated revisions

Revision eea81e81
Added by Giuseppe Sucameli over 8 years ago

[DBManager] remove layers from QgsMapLayerRegistry once refreshing a table, previewing a different layer or closing the DBManager main window (fix #12938)


#1 Updated by Giovanni Manghi over 8 years ago

  • Category set to DB Manager

#2 Updated by Giuseppe Sucameli over 8 years ago

  • OS version deleted (OpenSUSE 13.2)
  • Operating System deleted (Linux)
  • Assignee set to Giuseppe Sucameli

That's layer registry, not TOC...
Anyway layers must be removed either once the preview changes or the DBManager main window is closed.
I'm looking at it.

#3 Updated by Giuseppe Sucameli over 8 years ago

  • Status changed from Open to Closed

Also available in: Atom PDF