Mercurial's demandload system is incompatible with sqlalchemy.
This was reported upstream as
https://bz.mercurial-scm.org/show_bug.cgi?id=5085
and is available in the upstream repository in changesets c25e3fd38ff1 and
9ff7261cc0f5.
diff --git a/mercurial/demandimport.py b/mercurial/demandimport.py
--- a/mercurial/demandimport.py
+++ b/mercurial/demandimport.py
@@ -174,7 +174,12 @@ def _demandimport(name, globals=None, lo
"""
symbol = getattr(mod, attr, nothing)
if symbol is nothing:
- symbol = _demandmod(attr, mod.__dict__, locals, level=1)
+ mn = '%s.%s' % (mod.__name__, attr)
+ if mn in ignore:
+ importfunc = _origimport
+ else:
+ importfunc = _demandmod
+ symbol = importfunc(attr, mod.__dict__, locals, level=1)
setattr(mod, attr, symbol)
# Record the importing module references this symbol so we can
@@ -250,6 +255,7 @@ ignore = [
'_sre', # issue4920
'rfc822',
'mimetools',
+ 'sqlalchemy.events', # has import-time side effects (issue5085)
# setuptools 8 expects this module to explode early when not on windows
'distutils.msvc9compiler'
]