Bug report #812

QGIS crashes while loading PostGIS layer with insufficient permissions

Added by horst-duester - over 16 years ago. Updated over 14 years ago.

Status:Closed
Priority:Low
Assignee:Jürgen Fischer
Category:Data Provider
Affected QGIS version: Regression?:No
Operating System:RedHat Easy fix?:No
Pull Request or Patch supplied: Resolution:fixed
Crashes QGIS or corrupts data: Copied to github as #:10871

Description

When you try to load a PostGIS Layer with insufficient permissions, a message box appears and after clicking OK QGIS crashes.

Associated revisions

Revision 9417efc9
Added by Jürgen Fischer over 16 years ago

add only valid layers, fixes #812

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7624 c8812cc2-4d05-0410-92ff-de0c093fc19c

Revision 4dbc0bc5
Added by Jürgen Fischer over 16 years ago

add only valid layers, fixes #812

git-svn-id: http://svn.osgeo.org/qgis/trunk@7624 c8812cc2-4d05-0410-92ff-de0c093fc19c

History

#1 Updated by Jürgen Fischer over 16 years ago

  • Status changed from Open to In Progress

Actually I get two dialogs, the first informs about the insufficient privileges on teh selected table (ie. permission denied on relation) and the second about the layer being invalid. But no crash.

Anything special to reproduce this?

#2 Updated by horst-duester - over 16 years ago

OK you are right when you load the layer via standard PostGIS loader in GUI. I load the layer via Python Script with the following lines:

... snip

      uri = [[QgsDataSourceURI]]()
      uri.setConnection(hostname, port, dbname, username, "")
      uri.setDataSource(schema, table, geom_col, "")
      vlayer = [[QgsVectorLayer]](uri.text(), layerName, "postgres")        

      canvas = self.iface.getMapCanvas()
      [[QgsMapLayerRegistry]].instance().addMapLayer(vlayer)

snip ...

Try to load a layer with insufficient permissions. You will get a different message box (white with PostgreSQL error message). After click on OK QGIS crash.

#3 Updated by Martin Dobias over 16 years ago

After creating an instance of a layer, you must ensure that vector layer is loaded correctly - if not, further behaviour is undefined.

if not vlayer.isValid():
  print "Couldn't load layer!" 

#4 Updated by horst-duester - over 16 years ago

wonder thank you for the workaround. Isn't it better to ensure the correct load of the layer at the provider?

#5 Updated by Martin Dobias over 16 years ago

Well, this check is not really a workaround, it's the thing you have to do always when loading a layer. The problem here is that all the initialization happens in constructor and constructors can't return any value to tell you whether the initialization went fine, so you need to call isValid() to find it out. Once we will be free to do some bigger modification to QGIS API it's likely that this will be changed somehow.

However it's true that QGIS shouldn't crash even if you're trying to access invalid layer.

Martin

#6 Updated by Jürgen Fischer over 16 years ago

  • Status changed from In Progress to Closed
  • Resolution set to fixed

fixed in 4dbc0bc5 (SVN r7625)

#7 Updated by Anonymous over 14 years ago

Milestone Version 0.9.1 deleted

Also available in: Atom PDF