Skip to content

Commit 68b7bf6

Browse files
committedFeb 3, 2018
[dbmanager] porting of dae921c to 3: fixes #16476
1 parent 639d310 commit 68b7bf6

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed
 

‎python/plugins/db_manager/db_plugins/vlayers/connector.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ def getLayer(self, l):
9696
lid = self.layers.get(l)
9797
if lid is None:
9898
return lid
99+
if lid not in QgsProject.instance().mapLayers().keys():
100+
self.layers.pop(l)
101+
return None
99102
return QgsProject.instance().mapLayer(lid)
100103

101104

@@ -249,12 +252,16 @@ def getRasterTables(self, schema=None):
249252
def getTableRowCount(self, table):
250253
t = table[1]
251254
l = VLayerRegistry.instance().getLayer(t)
255+
if not l or not l.isValid():
256+
return None
252257
return l.featureCount()
253258

254259
def getTableFields(self, table):
255260
""" return list of columns in table """
256261
t = table[1]
257262
l = VLayerRegistry.instance().getLayer(t)
263+
if not l or not l.isValid():
264+
return []
258265
# id, name, type, nonnull, default, pk
259266
n = l.dataProvider().fields().size()
260267
f = [(i, f.name(), f.typeName(), False, None, False)
@@ -280,6 +287,8 @@ def getTableExtent(self, table, geom):
280287
l = QgsProject.instance().mapLayer(t)
281288
else:
282289
l = VLayerRegistry.instance().getLayer(t)
290+
if not l or not l.isValid():
291+
return None
283292
e = l.extent()
284293
r = (e.xMinimum(), e.yMinimum(), e.xMaximum(), e.yMaximum())
285294
return r

‎python/plugins/db_manager/layer_preview.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,16 @@ def _loadTablePreview(self, table, limit=False):
113113
else:
114114
vl = table.toMapLayer()
115115

116-
if not vl.isValid():
116+
if vl and not vl.isValid():
117117
vl.deleteLater()
118118
vl = None
119119

120120
# remove old layer (if any) and set new
121121
if self.currentLayer:
122-
QgsProject.instance().removeMapLayers([self.currentLayer.id()])
122+
if not QgsProject.instance().layerTreeRoot().findLayer(self.currentLayer.id()):
123+
QgsProject.instance().removeMapLayers([self.currentLayer.id()])
123124

124-
if vl:
125+
if vl and vl.isValid():
125126
self.setLayers([vl])
126127
QgsProject.instance().addMapLayers([vl], False)
127128
self.zoomToFullExtent()

0 commit comments

Comments
 (0)
Please sign in to comment.