Skip to content

Commit eed42b1

Browse files
committedJun 29, 2018
[python] Block imports of PyQt4 modules
Prevents crashes when PyQt4 modules are imported in QGIS 3.x. This instantly segfaults QGIS. Throwing an exception makes it easier to identify the cause as a faulty plugin, and shows exactly where the bad import is located. (cherry-picked from dbac3b4)
1 parent 703a6be commit eed42b1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed
 

‎python/utils.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,18 @@ def __exit__(self, exc_type, exc_val, exc_tb):
659659

660660

661661
def _import(name, globals={}, locals={}, fromlist=[], level=None):
662-
""" wrapper around builtin import that keeps track of loaded plugin modules """
662+
"""
663+
Wrapper around builtin import that keeps track of loaded plugin modules and blocks
664+
certain unsafe imports
665+
"""
663666
if level is None:
664667
level = 0
668+
669+
if 'PyQt4' in name:
670+
msg = 'PyQt4 classes cannot be imported in QGIS 3.x.\n' \
671+
'Use {} or the version independent {} import instead.'.format(name.replace('PyQt4', 'PyQt5'), name.replace('PyQt4', 'qgis.PyQt'))
672+
raise ImportError(msg)
673+
665674
mod = _builtin_import(name, globals, locals, fromlist, level)
666675

667676
if mod and '__file__' in mod.__dict__:

0 commit comments

Comments
 (0)
Please sign in to comment.