-
Notifications
You must be signed in to change notification settings - Fork 199
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
Mitogen broken by distro 1.7.0 #906
Comments
arch linux, ansible v2.12.2, python v3.10.2 - same issue |
While that's how the bug was described to me, from my own experimentation, I'd describe it as: Upgrading distro from 1.6.0 to 1.7.0 on the controller broke the use-case when the target doesn't have distro installed. |
ansible.module_utils.distro replaces itself with either the distro module, when it exists, or the bundled distro module. If a target doesn't have a system distro module, it will try to load the bundled distro module (ansible.module_utils.distro._distro). This is tricky, because sys.modules['ansible.module_utils.distro'] points to the distro package. ParentEnumerationMethod() walks up the module tree, to get above this misdirection. The change from a module to package in distro 1.7.0 broke ParentEnumerationMethod's heuristics. Hardcode avoiding the module 'ansible.module_utils.distro' as an import starting point. Fixes: mitogen-hq#906
ansible.module_utils.distro replaces itself with either the distro module, when it exists, or the bundled distro module. If a target doesn't have a system distro module, it will try to load the bundled distro module (ansible.module_utils.distro._distro). This is tricky, because sys.modules['ansible.module_utils.distro'] points to the distro package. ParentEnumerationMethod() walks up the module tree, to get above this misdirection. The change from a module to package in distro 1.7.0 broke ParentEnumerationMethod's heuristics. Hardcode avoiding the module 'ansible.module_utils.distro' as an import starting point. Fixes: mitogen-hq#906
When the requested module (e.g. ansible.module_utils.distro) - is provided by another module *e.g. distro) - that itself was a package (e.g. distro 1.7.0) At runtime - ansible/module_utils/distro/__init__.py executes - if https://pypi.org/project/distro/ is present, it's loaded as ansible.module_utils.distro - otherwise ansible/module_utils/distro/_distro.py is loaded ParentEnumerationMethod would wrongly use whatever was in sys.modules['ansible.module_utils.distro]. Instead we should ascend to the first parent that has fullname == sys.modules[fullname].__name__. Then descend to the appropriate .py file on disk. This bug didn't show up before because until distro 1.7.0 (Feb 2022) the top-level distro module was a module (distro.py) not a package (distro/__init__.py) fixes mitogen-hq#906
When the requested module (e.g. ansible.module_utils.distro) - is provided by another module *e.g. distro) - that itself was a package (e.g. distro 1.7.0) At runtime - ansible/module_utils/distro/__init__.py executes - if https://pypi.org/project/distro/ is present, it's loaded as ansible.module_utils.distro - otherwise ansible/module_utils/distro/_distro.py is loaded ParentEnumerationMethod would wrongly use whatever was in sys.modules['ansible.module_utils.distro]. Instead we should ascend to the first parent that has fullname == sys.modules[fullname].__name__. Then descend to the appropriate .py file on disk. This bug didn't show up before because until distro 1.7.0 (Feb 2022) the top-level distro module was a module (distro.py) not a package (distro/__init__.py) fixes mitogen-hq#906
Based on @stefanor's branch I think I've prototyped a more general fix willmerae@754a94b. Would anyone be willing to try it? I'll create a PR once I've teased out some refactoring from the messy investigation branch https://github.com/willmerae/mitogen/tree/issue-906. |
Oh, yeah, that definitely looks cleaner. |
When the requested module (e.g. ansible.module_utils.distro) - is provided by another module *e.g. distro) - that itself was a package (e.g. distro 1.7.0) At runtime - ansible/module_utils/distro/__init__.py executes - if https://pypi.org/project/distro/ is present, it's loaded as ansible.module_utils.distro - otherwise ansible/module_utils/distro/_distro.py is loaded ParentEnumerationMethod would wrongly use whatever was in sys.modules['ansible.module_utils.distro]. Instead we should ascend to the first parent that has fullname == sys.modules[fullname].__name__. Then descend to the appropriate .py file on disk. This bug didn't show up before because until distro 1.7.0 (Feb 2022) the top-level distro module was a module (distro.py) not a package (distro/__init__.py) fixes mitogen-hq#906
Co-authored-by: Stefano Rivera <[email protected]> When the requested module (e.g. ansible.module_utils.distro) - is provided by another module *e.g. distro) - that itself was a package (e.g. distro 1.7.0) At runtime - ansible/module_utils/distro/__init__.py executes - if https://pypi.org/project/distro/ is present, it's loaded as ansible.module_utils.distro - otherwise ansible/module_utils/distro/_distro.py is loaded ParentEnumerationMethod would wrongly use whatever was in sys.modules['ansible.module_utils.distro]. Instead we should ascend to the first parent that has fullname == sys.modules[fullname].__name__. Then descend to the appropriate .py file on disk. This bug didn't show up before because until distro 1.7.0 (Feb 2022) the top-level distro module was a module (distro.py) not a package (distro/__init__.py) fixes mitogen-hq#906
Co-authored-by: Stefano Rivera <[email protected]> When the requested module (e.g. ansible.module_utils.distro) - is provided by another module *e.g. distro) - that itself was a package (e.g. distro 1.7.0) At runtime - ansible/module_utils/distro/__init__.py executes - if https://pypi.org/project/distro/ is present, it's loaded as ansible.module_utils.distro - otherwise ansible/module_utils/distro/_distro.py is loaded ParentEnumerationMethod would wrongly use whatever was in sys.modules['ansible.module_utils.distro]. Instead we should ascend to the first parent that has fullname == sys.modules[fullname].__name__. Then descend to the appropriate .py file on disk. This bug didn't show up before because until distro 1.7.0 (Feb 2022) the top-level distro module was a module (distro.py) not a package (distro/__init__.py) fixes mitogen-hq#906
This drops ansible 2.x compatibility as upstream ansible version is also no longer supported. Includes backported fix for #906, which breaks mitogen if py-distro is also installed. mitogen-hq/mitogen#906 Sponsored by: SkunkWerks, GmbH
From https://bugs.debian.org/1006330:
Something like issue #590 (see: #610, #622) seems to be back with distro 1.7.0. Presumably because of the change of module layout in python-distro/distro#315
With the Debian packaged ansible 2.10.8, mitogen 0.3.1, on Python 3.9.8. Upgrading from distro 1.6.0 to 1.7.0 on the target broke mitogen:
The text was updated successfully, but these errors were encountered: