Skip to content
Permalink
Browse files

[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)
  • Loading branch information
nyalldawson committed Jun 28, 2018
1 parent 703a6be commit eed42b17d436bed1fc0b0319643c15c2c462f3d7
Showing with 10 additions and 1 deletion.
  1. +10 −1 python/utils.py
@@ -659,9 +659,18 @@ def __exit__(self, exc_type, exc_val, exc_tb):


def _import(name, globals={}, locals={}, fromlist=[], level=None):
""" wrapper around builtin import that keeps track of loaded plugin modules """
"""
Wrapper around builtin import that keeps track of loaded plugin modules and blocks
certain unsafe imports
"""
if level is None:
level = 0

if 'PyQt4' in name:
msg = 'PyQt4 classes cannot be imported in QGIS 3.x.\n' \
'Use {} or the version independent {} import instead.'.format(name.replace('PyQt4', 'PyQt5'), name.replace('PyQt4', 'qgis.PyQt'))
raise ImportError(msg)

mod = _builtin_import(name, globals, locals, fromlist, level)

if mod and '__file__' in mod.__dict__:

0 comments on commit eed42b1

Please sign in to comment.
You can’t perform that action at this time.