qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.59k stars 3.01k forks source link

Calling QgsPathResolver.setPathPreprocessor causes python to abort #58112

Open rbrooklyn opened 3 months ago

rbrooklyn commented 3 months ago

What is the bug or the crash?

Calling QgsPathResolver.setPathPreprocessor() causes Python to abort without any error message.

This has been observed on version 3.34.8 and 3.34.7 for Windows 10 on two different machines.

This has worked absolutely fine 3.28.x for Windows 10 in the past. I've only noticed an issue when updating QGIS and running existing scripts.

Steps to reproduce the issue

Create Test.py with the following contents:

from qgis.core import QgsApplication, QgsProject, QgsLayoutExporter, QgsPathResolver from osgeo import gdal import os import sys

def my_path_processor(path): print(f"my_path_processor() called with {{path}}")

qgs = QgsApplication([], False) print("1") qgs.initQgis() print("2") QgsPathResolver.setPathPreprocessor(my_path_processor) print("3") qgs.exitQgis() print("4")

Run C:\Program Files\QGIS 3.34.8\bin\python-qgis-ltr.bat .\Test.py

Output should be:

1 2 3 4

Output is actually

1 2

As when the "QgsPathResolver.setPathPreprocessor(my_path_processor)" line is called then python closes without proceeding so the print lines for 3 and 4 are never called.

Versions

QGIS version | 3.34.8-Prizren | QGIS code revision | 91642333 -- | -- | -- | -- Qt version | 5.15.13 Python version | 3.12.4 GDAL/OGR version | 3.9.0 PROJ version | 9.4.0 EPSG Registry database version | v11.004 (2024-02-24) GEOS version | 3.12.2-CAPI-1.18.2 SQLite version | 3.45.1 PDAL version | 2.6.3 PostgreSQL client version | 16.2 SpatiaLite version | 5.1.0 QWT version | 6.2.0 QScintilla2 version | 2.14.1 OS version | Windows Server 2022 Version 2009   |   |   |   Active Python plugins changeDataSource | 3.1 db_manager | 0.1.20 grassprovider | 2.12.99 MetaSearch | 0.3.6 processing | 2.12.99 QGIS version 3.34.8-Prizren QGIS code revision [91642333](https://github.com/qgis/QGIS/commit/91642333) Qt version 5.15.13 Python version 3.12.4 GDAL/OGR version 3.9.0 PROJ version 9.4.0 EPSG Registry database version v11.004 (2024-02-24) GEOS version 3.12.2-CAPI-1.18.2 SQLite version 3.45.1 PDAL version 2.6.3 PostgreSQL client version 16.2 SpatiaLite version 5.1.0 QWT version 6.2.0 QScintilla2 version 2.14.1 OS version Windows Server 2022 Version 2009 Active Python plugins changeDataSource 3.1 db_manager 0.1.20 grassprovider 2.12.99 MetaSearch 0.3.6 processing 2.12.99 ### Supported QGIS version - [X] I'm running a supported QGIS version according to [the roadmap](https://www.qgis.org/en/site/getinvolved/development/roadmap.html#release-schedule). ### New profile - [x] I tried with a new [QGIS profile](https://docs.qgis.org/latest/en/docs/user_manual/introduction/qgis_configuration.html#working-with-user-profiles) ### Additional context _No response_
rbrooklyn commented 3 months ago

Test.py file attached for reference. Remove .txt suffix as github wouldn't allow a .py suffixed file. Test.py.txt

rbrooklyn commented 3 months ago

Bit more testing today. Looks like this works very well in 3.38.0

Running & "C:\Program Files\QGIS 3.38.0\bin\python-qgis.bat" .\Test.py in powershell produced the expected result.

Running my actual scripts against 3.38.0 also worked without issue. I'd prefer to use the LTR version if possible, and this probably still needs fixing, but this is a workaround

dmarteau commented 1 month ago

I Confirm that calling QgsPathResolver.setPathPreprocessor from python cause a segmentation fault

QGIS: 3.34.11 (ltr) Ubuntu: 24.04 Python: 3.12.3

The method does not crash with QGIS 3.38.3 (release) on the same platform.