-
-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
python dataclasses seems to look in sys.modules[__module__], so all dynamic loading patterns would need to add there too (which...how do you clean up ...shrugs) #1419
Comments
Hi, The linked issues seems to provide the solution, ie manually adding the module to the sys.modules dict. |
Interestingly when alembic still supported py27 this code actively removed the module from sys.modules in the py2 code: alembic/alembic/util/compat.py Lines 176 to 241 in b1e5a23
But I guess if the current behaviour is wanted we could add the module to |
it is on purpose, since these aren't "modules" that are imported by "import", and I didnt think we wanted these python modules to live in the Python interpreter permanently until the interpreter ends..there could be hundreds of files taking up memory etc. we do the same thing in mako FYI. so...might want to try over there too. |
well in python2 alembic was quite blunt about it Alternatively, since this seems a very rare case we do a "try current version; catch Attribute error and re-try with the module added in sys.modules"? |
trying to clean up after the fact seems kind of messy at the moment I feel like new config flag in alembic.ini that turns on "add to sys.modules ; note: migration files will remain persistent in the python interpreter until interpreter close unless removed manually" somethign like that |
don't really like having yet another config knob, but it's probably the best option |
any chance someone reported this as a shortcoming in python dataclasses? |
I think what python does here is very similar to what sqlalchemy does to evaluate a string annotation: exec it using the module dict to use the proper globals. Not sure if anything different could be done in the dataclass module |
honestly I'm not 100% it makes sense adding a new config flag just for this, since it's utility seems very low. I'm for closing with "won't fix", since the workaround is simple: define the dataclass on another module and import it from the migration. |
OK that's fine |
Thanks for having a look |
Describe the bug
If
from __future__ import annotations
is used with adataclass
, alembic crashesExpected behavior
No crash
To Reproduce
alembic heads
Error
Versions.
Additional context
Found also other project suffering from this issue: mkdocs/mkdocs#3141
Have a nice day!
The text was updated successfully, but these errors were encountered: