Skip to content

Add WMS server fails with QGIS Server with Postgresql project #31192

Description

@jgrocha

Context

QGIS desktop should be able to work with QGIS Server, if the project is stored in Postgresql.

When QGIS Server is used with several different projects, the MAP parameter must be present to tell which project to use.

The following GetCapabilities requests are used against two different projects: one stored on the server filesystem and another stored in Postgresql:

  1. http://qgis.demo/cgi-bin/qgis_mapserv.fcgi?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities&MAP=/home/qgis/projects/cartageologica.qgz
  2. http://qgis.demo/cgi-bin/qgis_mapserv.fcgi?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities&MAP=postgresql%3A%3Fservice%3Dpg_geotuga%26sslmode%3Ddisable%26dbname%3D%26schema%3Dortos%26project%3Dteste

The second URL, which includes the Postgresql project, must be properly quoted to be properly handled on the QGIS Server side:

python -c "import urllib, sys; print urllib.quote(sys.argv[1])" "postgresql:?service=pg_geotuga&sslmode=disable&dbname=&schema=ortos&project=teste"

Describe the bug

There is no problem to add a QGIS Server url to QGIS desktop, using a MAP=<project on filesystem>.

wms with project from filesystem

There is no way to add QGIS Server urls with MAP=<Postgresql project>.

error add qis server with postgresql project

I've tried with both the quoted and unquoted URL:

  1. http://qgis.demo/cgi-bin/qgis_mapserv.fcgi?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities&MAP=postgresql%3A%3Fservice%3Dpg_geotuga%26sslmode%3Ddisable%26dbname%3D%26schema%3Dortos%26project%3Dteste
  2. http://qgis.demo/cgi-bin/qgis_mapserv.fcgi?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities&MAP=postgresql:?service=pg_geotuga&sslmode=disable&dbname=&schema=ortos&project=teste

The error is the same. The string passed to QGIS server is the same.

How to Reproduce

  1. Go to Add WMS/WMTS layer
  2. Add a QGIS Server with a URl that includes the Postgresql project
  3. Click connect to get the capabilities document
  4. The GetCapabilities fails.

QGIS and OS versions

  1. QGIS 3.8, 3.9-Master
  2. Ubuntu 19.04
  3. GDAL 3.0.1

Additional context

The server is able to answer only if the MAP string is quoted.

The entry point in the source code is the QgsWmsSettings::parseUri function.

This calls uri.setEncodedUri( uriString ); which does not properly quote the project part and send the request to the server like:
QUERY_STRING: VERSION=1.3.0&MAP=postgresql:?service=pg_geotuga&sslmode=disable&dbname=&schema=ortos&project=teste&SERVICE=WMS&REQUEST=GetCapabilities
The server breaks the parameters using the & character and the MAP becomes only:
21:04 INFO Server[7789]: MAP:postgresql:?service=pg_geotuga.

There are several possibilities...

  1. Change the postgresql project string format, removing the & (this might break existing projects, but using & will be always a problem). Better now than later.
  2. Make this uri.setEncodedUri( uriString ); function aware of the MAP parameter and create a proper quoted MAP string.
  3. Improve QGIS Server to recreate the proper MAP parameter. QGIS Server receives all the parameters, but separated by &.

Metadata

Metadata

Labels

BugEither a bug report, or a bug fix. Let's hope for the latter!PostGIS data providerProjectServerRelated to QGIS server

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions