3liz / py-qgis-server

QGIS embbeded WMS/WFS/WCS asynchronous scalable http server
https://docs.3liz.org/py-qgis-server
Mozilla Public License 2.0
68 stars 16 forks source link

Standard QGIS functions are not evaluated in docker lizmap qgis server during printing #18

Closed NyakudyaA closed 4 years ago

NyakudyaA commented 4 years ago

Procedure 3liz qgis server image

Print Request http://localhost:8091/ows/?DPI=100&EXCEPTIONS=application/vnd.ogc.se_inimage&FORMAT=pdf&LAYERS=index1in50k,ProvincialBoundary_sae&MAP=liz/error.qgs&MAP0:EXTENT=2972996.901597,-3761252.0445,3009497.779341,-3739151.513044&MAP0:GRID_INTERVAL_X=5000&MAP0:GRID_INTERVAL_Y=5000&MAP0:LAYERS=ProvincialBoundary_sae&MAP0:SCALE=100000&MAP0:STYLES=default,default&OPACITIES=255,255&REQUEST=GetPrint&SERVICE=WMS&SRS=EPSG:3857&STYLES=default,default&TEMPLATE=map&TRANSPARENT=true&VERSION=1.3.0

Print Request Image

print-error

Image version vers

Procedure camp to camp image

docker run -d -p 8380:80 -v `pwd`/liz:/etc/qgisserver -e QGIS_PROJECT_FILE=/etc/qgisserver/error.qgs camptocamp/qgis-server:3.14

Print Request http://localhost:8380/ows/?DPI=100&EXCEPTIONS=application/vnd.ogc.se_inimage&FORMAT=pdf&LAYERS=index1in50k,ProvincialBoundary_sae&MAP=/etc/qgisserver/error.qgs.qgs&MAP0:EXTENT=2972996.901597,-3761252.0445,3009497.779341,-3739151.513044&MAP0:GRID_INTERVAL_X=5000&MAP0:GRID_INTERVAL_Y=5000&MAP0:LAYERS=ProvincialBoundary_sae&MAP0:SCALE=100000&MAP0:STYLES=default,default&OPACITIES=255,255&REQUEST=GetPrint&SERVICE=WMS&SRS=EPSG:3857&STYLES=default,default&TEMPLATE=map&TRANSPARENT=true&VERSION=1.3.0

Print Request Image

image-print

liz.zip

Gustry commented 4 years ago

@dmarteau Should we move this issue to https://github.com/3liz/py-qgis-server ?

dmarteau commented 4 years ago

Please move the issue to the appropriate project...

Gustry commented 4 years ago

Please move the issue to the appropriate project...

There is a button for that ;-)

This is not related to Lizmap @NyakudyaA

dmarteau commented 4 years ago

@NyakudyaA: py-qgis-server use the official qgis debian distribution https://www.qgis.org/en/site/forusers/alldownloads.html#debian-ubuntu and is a python layer over the qgis server API.

I don't know how it differs from the camptocamp image since I couldn't find their Dockerfile, but as we pass all requests to the API, it may be a problem with the official distro. We need to check it out...

NyakudyaA commented 4 years ago

Thanks @Gustry i was printing initially from lizmap webclient then noticed this behavior. I then setup the individual containers to try to debug what was happening

dmarteau commented 4 years ago

@rldhont @Gustry An Idea why qgis would not evaluate function ?

dmarteau commented 4 years ago

@NyakudyaA Did you try a GetMap request ?

NyakudyaA commented 4 years ago

@NyakudyaA Did you try a GetMap request ?

getmap request are working fine

NyakudyaA commented 4 years ago

@NyakudyaA: py-qgis-server use the official qgis debian distribution https://www.qgis.org/en/site/forusers/alldownloads.html#debian-ubuntu and is a python layer over the qgis server API.

I don't know how it differs from the camptocamp image since I couldn't find their Dockerfile, but as we pass all requests to the API, it may be a problem with the official distro. We need to check it out...

You can also try to run the https://github.com/gem/oq-qgis-server. It has a Dockerfile visible and correctly evaluates as well

dmarteau commented 4 years ago

getmap request are working fine

Interesting, so its seems that expressions are not evaluated only in the context of a getprint

dmarteau commented 4 years ago

You can also try to run the https://github.com/gem/oq-qgis-server. It has a Dockerfile visible and correctly evaluates as well

@NyakudyaA Thx for the tip, also there is no différence the way Qgis is installed, the only difference is how the server is run:

I suspect a missing configuration that would prevent getprint to evaluate function in the context of the server.

dmarteau commented 4 years ago

@rldhont @Gustry I found that: if the we create the project from the QgsConfigCache then the getPrint evaluate correctly the function but if we create the project explicitely with QgsProject() then the getPrint does not evaluate functions.

So

settings = QgsServerSettings()
project = QgsConfigCache.instance().project( config_path, settings )
server.handleRequest(request, response, project=project)

does lead to correct getPrint() request, while

project = QgsProject()
project.read( config_path )
server.handleRequest(request, response, project=project)

will occurs in incorrect getPrint().

Looking at the 3.10 source code of QgsConfigCache, the cache does nothing more (except for bad layer handler): So I suspect that the getPrint() code use the default config cache at some point. @rldhont @Gustry any clue ?

dmarteau commented 4 years ago

@rldhont @Gustry I think I have found the problem: the QgsConfigCache do QgsProject::setInstance(...), I suspect that some internal qgis still use the QgsProject::instance method (seems to be removed since Qgis 3.15).

If you instanciate the QgsProject and pass it to the server then you bypass the QgsConfigCache and the setInstance is never called. Infortunatly this method is not accessible from python, so this defeat the purpose to explicitely pass a QgsProject to the handleRequest method.

We need to make a PR to fix the problem so that QgsProject::setInstance is called whe we pass a project or eventually expose the setInstance method.

Remember that we do not use the QgsConfigCache because is does support nothing else that project files - and we want to support alternative storage (aka postgres storage)

dmarteau commented 4 years ago

I confirm that running a qgis server with patch applied to call QgsProject:setInstance() solve the problem.

dmarteau commented 4 years ago

@rldhont can you call for review https://github.com/qgis/QGIS/pull/38488 ?

dmarteau commented 4 years ago

The fix has been accepted and backported to 3.10 and 3.14

@NyakudyaA we wait for the next qgis minor release to confirm the fix.

NyakudyaA commented 4 years ago

The fix has been accepted and backported to 3.10 and 3.14

* [qgis/QGIS#38508](https://github.com/qgis/QGIS/pull/38508)

* [qgis/QGIS#38509](https://github.com/qgis/QGIS/pull/38509)

@NyakudyaA we wait for the next qgis minor release to confirm the fix.

Thanks a lot for spotting the bug. I will wait for the bugfix and then test

dmarteau commented 4 years ago

Fixed and backported to qgis 3.10