Opened 16 years ago

Closed 16 years ago

Last modified 15 years ago

#812 closed bug (fixed)

QGIS crashes while loading PostGIS layer with insufficient permissions

Reported by: horst.duester Owned by: jef
Priority: major: does not work as expected Milestone:
Component: Data Provider Version: Trunk
Keywords: Cc:
Must Fix for Release: Yes Platform: RedHat
Platform Version: Awaiting user input: yes

Description

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

Change History (7)

comment:1 by jef, 16 years ago

Awaiting user input: set
Owner: changed from nobody to jef
Status: newassigned

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?

comment:2 by horst.duester, 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.

comment:3 by wonder, 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!"

comment:4 by horst.duester, 16 years ago

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

comment:5 by wonder, 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

comment:6 by jef, 16 years ago

Resolution: fixed
Status: assignedclosed

fixed in r7624

comment:7 by (none), 15 years ago

Milestone: Version 0.9.1

Milestone Version 0.9.1 deleted

Note: See TracTickets for help on using tickets.