Closed sqlalchemy-bot closed 6 years ago
Barry Warsaw (warsaw) wrote:
FWIW, I don't believe it's a bug in module_from_spec()
. I think you've found the root cause of the bug.
Michael Bayer (zzzeek) wrote:
There's no bug in Alembic here because env.py is treated as a single-use script, not an importable module, and the fact that it does not pollute sys.modules is by design. The implementation that uses load_module() removes the name from sys.modules immediately, so even with that version, env.py is not available to import by other parts of the application. This implemetantation was modified in #449 to work around deprecation warnings in Python 3.5 and 3.6.
I just took a look at atpublic and this library is not appropriate for an env.py script. There's no reason to place __all__
into env.py because env.py is not meant to be imported. To allow for env.py to be importable as a normal module would require some feature that allows for a user-defined module to be located by a traditional module name rather than a file location relative to the configured alembic migrations directory; it's not appropriate to use "env" as the full module name as this is too ambiguous and would conflict with other applications and Alembic migration environments trying to do the same thing. However, this feature already exists - just go into the "env.py" script, move its entire contents into whatever application module you'd like, then change env.py itself to just import that module and do nothing else.
Barry Warsaw (warsaw) wrote:
Thanks for the explanation! I'll just remove the use of @public
from this module.
Michael Bayer (zzzeek) wrote:
Great, thanks
Migrated issue, originally created by Abhilash Raj (maxking)
load_module_py
andload_module_pyc
for Python 3.5 in alembic.utils don't initialize the module properly before executing them.This bug was found in latest release of alembic when using
@public
inenv.py
:Looks like
load_module_py
doesn't add the module tosys.modules
which causes the error. The oldload_module
API did this automatically.I am not sure if
module_from_spec
should take care of this (i.e. it is a bug in stdlib) or it should be addressed in alembic.