Skip to content

QGIS Server ignores MAP override when QGIS_PROJECT_FILE is set #64723

Description

@zxmarcos

What is the bug or the crash?

I wrote a simple QGIS Server plugin that redirects the MAP parameter based on a UUID, so clients don’t need to know the filesystem path of the project.

However, when the environment variable QGIS_PROJECT_FILE is defined, QGIS Server ignores any attempt to change the project at runtime.
Both changing the MAP parameter, and calling setConfigFilePath() stop working if QGIS_PROJECT_FILE exists.

If QGIS_PROJECT_FILE is defined:

  • The log shows the redirect
  • But QGIS Server always loads the project from the environment variable
  • The MAP change and setConfigFilePath() are ignored (log Changing the 'MAP' parameter will have no effect on config path: use QgsSerververInterface::setConfigFilePath instead)
  • If QGIS_PROJECT_FILE is not set, the plugin works correctly.

Steps to reproduce the issue

Call request.setParameter('MAP', project_file) or self.serverInterface().setConfigFilePath(project_file) inside requestReady method in QgsServerFilter

Versions

QGIS Server Starting : 3.42.0-Münster (feb8023)

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

Additional context

Filter source code:

from qgis.server import QgsServerFilter
from qgis.core import QgsMessageLog
import os
import re

class MyFilter(QgsServerFilter):

    def __init__(self, serverIface):
        super(MyFilter, self).__init__(serverIface)

    def requestReady(self):
        projectpath = self.serverInterface().configFilePath()
        request = self.serverInterface().requestHandler()
        params = request.parameterMap()

        map_param = params.get('MAP', '')
        if map_param:
            if re.match(r'^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$', map_param):
                projects_dir = os.environ.get(
                    'MY_PROJECTS_DIR',
                    os.path.join(os.path.dirname(projectpath), 'projects')
                )
                project_file = os.path.join(projects_dir, f"{map_param}.qgs")

                if os.path.exists(project_file):
                    QgsMessageLog.logMessage(f"Redirecting MAP {map_param} to {project_file}")
                    request.setParameter('MAP', project_file)
                    self.serverInterface().setConfigFilePath(project_file)

Qgis server log:

17:55:44 INFO Server[71]: ******************** New request ***************

17:55:44 INFO Server[71]: Request URL: [http://localhost:9003/qgis?SERVICE=WMS&REQUEST=GetCapabilities&MAP=817582b9-008c-427c-bafa-9fbec82a2830⁠](http://localhost:9003/qgis?SERVICE=WMS&REQUEST=GetCapabilities&MAP=817582b9-008c-427c-bafa-9fbec82a2830)

17:55:44 INFO Server[71]: Environment:

17:55:44 INFO Server[71]: ------------------------------------------------

17:55:44 INFO Server[71]: SERVER_NAME: localhost

17:55:44 INFO Server[71]: REQUEST_URI: /qgis?SERVICE=WMS&REQUEST=GetCapabilities&MAP=817582b9-008c-427c-bafa-9fbec82a2830

17:55:44 INFO Server[71]: SCRIPT_NAME: /qgis

17:55:44 INFO Server[71]: REMOTE_ADDR: 172.18.0.1

17:55:44 INFO Server[71]: SERVER_PORT: 9003

17:55:44 INFO Server[71]: QUERY_STRING: SERVICE=WMS&REQUEST=GetCapabilities&MAP=817582b9-008c-427c-bafa-9fbec82a2830

17:55:44 INFO Server[71]: REQUEST_METHOD: GET

17:55:44 INFO Server[71]: QGIS_PROJECT_FILE: /etc/qgisserver/projects/project.qgs

17:55:44 INFO Server[71]: QGIS_SERVER_IGNORE_BAD_LAYERS: 1

17:55:44 INFO Server[71]: SERVER_PROTOCOL: HTTP/1.1

Headers:

------------------------------------------------

"Accept" :  "*/*"

"Host" :  "localhost:9003"

"User-Agent" :  "insomnia/2023.5.8"

17:55:44 WARNING [71]: Redirecting MAP 817582b9-008c-427c-bafa-9fbec82a2830 to /etc/qgisserver/projects/projects/817582b9-008c-427c-bafa-9fbec82a2830.qgs

17:55:44 WARNING Server[71]: Changing the 'MAP' parameter will have no effect on config path: use QgsSerververInterface::setConfigFilePath instead

17:55:44 WARNING [71]: ConfigFilePath /etc/qgisserver/projects/projects/817582b9-008c-427c-bafa-9fbec82a2830.qgs

17:55:44 INFO Server[71]: MAP:/etc/qgisserver/projects/projects/817582b9-008c-427c-bafa-9fbec82a2830.qgs

17:55:44 INFO Server[71]: REQUEST:GetCapabilities

17:55:44 INFO Server[71]: SERVICE:WMS

17:55:44 WARNING Server[71]: Found WMS capabilities document in cache

17:55:44 INFO Server[71]: Request finished in 6 ms

337366 - 172.18.0.1 - - [27/Jan/2026:17:55:44 +0000] "GET /qgis?SERVICE=WMS&REQUEST=GetCapabilities&MAP=817582b9-008c-427c-bafa-9fbec82a2830 HTTP/1.1" 200 4098 "-" "insomnia/2023.5.8"

Metadata

Metadata

Assignees

Labels

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

Type

No type
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