[PATCH] demandimport: fix level passed to loader of sub-modules

Augie Fackler raf at durin42.com
Fri Feb 5 10:42:41 EST 2016


On Thu, Feb 04, 2016 at 01:34:27PM -0800, Danek Duvall wrote:
> Pierre-Yves David wrote:
>
> > On 11/08/2015 11:05 AM, Gregory Szorc wrote:
> > >On Sat, Nov 7, 2015 at 11:39 AM, Pierre-Yves David
> > ><pierre-yves.david at ens-lyon.org <mailto:pierre-yves.david at ens-lyon.org>>
> > >wrote:
> > >
> > >
> > >
> > >    On 11/07/2015 10:49 AM, Gregory Szorc wrote:
> > >
> > >        On Mon, Nov 2, 2015 at 6:10 AM, Yuya Nishihara <yuya at tcha.org
> > >        <mailto:yuya at tcha.org>
> > >        <mailto:yuya at tcha.org <mailto:yuya at tcha.org>>> wrote:
> > >
> > >             # HG changeset patch
> > >             # User Yuya Nishihara <yuya at tcha.org <mailto:yuya at tcha.org>
> > >        <mailto:yuya at tcha.org <mailto:yuya at tcha.org>>>
> > >             # Date 1446380349 -32400
> > >             #      Sun Nov 01 21:19:09 2015 +0900
> > >             # Node ID d779ddd9edd51273de2754748dfcc0db1e1e0f72
> > >             # Parent  58b7f3e93bbab749ab16c09df12aae5ba7880708
> > >             demandimport: fix level passed to loader of sub-modules
> > >
> > >
> > >    I've pushed that one to the clowncopter.
> > >
> > >    Thanks goes to Greg for the review.
> > >
> > >
> > >Come to think of it, this patch should probably be for stable because
> > >without it, "from ..X import Y" will be broken. This could prevent 3rd
> > >party extensions which load 3rd party Python packages from working
> > >correctly. I /think/ this is a regression in 3.6 from my demandimport
> > >refactoring.
> >
> > I've move the fix to stable. Thanks for your input.
>
> My apologies for the late testing; I was running the internal testsuite,
> but hadn't tried yet to update our internal extension, which uses
> SQLAlchemy, to work with the latest bits.  With 3.7.1:
>
>     $ python
>     >>> from mercurial import demandimport
>     >>> demandimport.enable()
>     >>> from sqlalchemy import create_engine
>     Traceback (most recent call last):
>       File "<stdin>", line 1, in <module>
>       File "/usr/lib/python2.7/vendor-packages/mercurial/demandimport.py", line 141, in _demandimport
>       return _hgextimport(_import, name, globals, locals, fromlist, level)
>       File "/usr/lib/python2.7/vendor-packages/mercurial/demandimport.py", line 53, in _hgextimport
>       return importfunc(name, globals, *args, **kwargs)
>       File "/usr/lib/python2.7/vendor-packages/sqlalchemy/__init__.py", line 9, in <module>
>       from .sql import (
>       File "/usr/lib/python2.7/vendor-packages/mercurial/demandimport.py", line 192, in _demandimport
>       fromlist, level)
>       File "/usr/lib/python2.7/vendor-packages/mercurial/demandimport.py", line 53, in _hgextimport
>       return importfunc(name, globals, *args, **kwargs)
>       File "/usr/lib/python2.7/vendor-packages/sqlalchemy/sql/__init__.py", line 91, in <module>
>       __go(locals())
>       File "/usr/lib/python2.7/vendor-packages/sqlalchemy/sql/__init__.py", line 89, in __go
>       from . import naming
>       File "/usr/lib/python2.7/vendor-packages/mercurial/demandimport.py", line 141, in _demandimport
>       return _hgextimport(_import, name, globals, locals, fromlist, level)
>       File "/usr/lib/python2.7/vendor-packages/mercurial/demandimport.py", line 53, in _hgextimport
>       return importfunc(name, globals, *args, **kwargs)
>       File "/usr/lib/python2.7/vendor-packages/sqlalchemy/sql/naming.py", line 129, in <module>
>       @event.listens_for(Index, "after_parent_attach")
>       File "/usr/lib/python2.7/vendor-packages/sqlalchemy/event/api.py", line 94, in decorate
>       listen(target, identifier, fn, *args, **kw)
>       File "/usr/lib/python2.7/vendor-packages/sqlalchemy/event/api.py", line 63, in listen
>       _event_key(target, identifier, fn).listen(*args, **kw)
>       File "/usr/lib/python2.7/vendor-packages/sqlalchemy/event/api.py", line 28, in _event_key
>       (identifier, target))
>     sqlalchemy.exc.InvalidRequestError: No such event 'after_parent_attach' for target '<class 'sqlalchemy.sql.schema.Index'>'
>
> Backing out this changeset (78d05778907b) fixes this particular problem.
>
> I tried adding
>
>     >>> demandimport.ignore.append("sqlalchemy")
>
> before the import, but it doesn't seem to make any difference.  I also
> tried "sqlalchemy.sql.naming" as suggested by the stack trace, and
> "sqlalchemy.sql" for good measure, but none of that helped.
>
> SQLAlchemy is version 0.9.8.
>
> What's worrying me right now is that while I've been testing and updating
> our extension for a few days now, I just started seeing this last night.  I
> noticed it for the first time when running a command that isn't part of the
> testsuite, and is where the sqlalchemy bits are imported.  It seemed like
> something to track down, so I started poking.
>
> My first thought was to add
>
>     from mercurial import demandimport
>     demandimport.ignore.extend(["sqlalchemy"])
>
> to the top of the extension, but that just caused the error to happen every
> single time, and the extension wouldn't load.  That in turn caused me to
> try the import in a program of its own, and thus the "simple" testcase
> above.
>
> Any ideas?  (Other than adding the command to the testsuite and running it
> sooner: already on the schedule.)

Please file a bug about this, and mark it as a regression. Note that
if you would have reported this a week ago (before the release), you
might have been eligible for a prize.

>
> Thanks,
> Danek
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list