Skip to content

Commit

Permalink
do not rely on provider-specific decodeUri() when running against QGIS
Browse files Browse the repository at this point in the history
versions < 3.42.1/3.40.5

See qgis/QGIS#60703
  • Loading branch information
alexbruy committed Feb 22, 2025
1 parent b7c784b commit 80dc502
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions g3w-admin/qdjango/utils/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from core.utils.projects import CoreMetaLayer
from core.utils import unicode2ascii
from .exceptions import QgisProjectLayerException
from qgis.core import QgsDataSourceUri, QgsProviderRegistry
from qgis.core import Qgis, QgsDataSourceUri, QgsProviderRegistry

import requests

Expand Down Expand Up @@ -89,10 +89,14 @@ def datasource2dict(datasource: str, provider: str) -> dict[str, str]:
:rtype: dict
"""

# first try with the provider specific method
parts = QgsProviderRegistry.instance().decodeUri(provider, datasource)
if parts:
return {k: str(v) for k, v in parts.items()}
# TODO: teprorarily safeguard with version check as QGIS < 3.42.1 and QGIS < 3.40.5
# have small bug in PostgreSQL data provider decodeUri(). For more details
# see https://github.com/qgis/QGIS/pull/60703
if Qgis.QGIS_VERSION_INT >= 34201 or Qgis.QGIS_VERSION_INT >= 34005:
# first try with the provider specific method
parts = QgsProviderRegistry.instance().decodeUri(provider, datasource)
if parts:
return {k: str(v) for k, v in parts.items()}

# data provider does not support decodeUri(), we need to process it manually
parts = {}
Expand Down

0 comments on commit 80dc502

Please sign in to comment.