Repository navigation
fix(plugins): evict failed sibling exec from sys.modules so later imports raise ModuleNotFoundError - #112444
Closed
Mzzj114 wants to merge 1 commit into
Closed
fix(plugins): evict failed sibling exec from sys.modules so later imports raise ModuleNotFoundError#112444Mzzj114 wants to merge 1 commit into
Mzzj114 wants to merge 1 commit into
Conversation
…orts raise ModuleNotFoundError load_plugin_module's sibling loop kept a half-initialized module in sys.modules when exec_module raised, so a plugin's later relative import raised uncatchable 'ImportError: cannot import name ...' instead of the ModuleNotFoundError its handlers expect. Mirror the main-module cleanup (sys.modules.pop on failure) in the sibling loop. Tests: tests/plugins/test_plugin_loader_sibling_cleanup.py — red on base for the two regression assertions, green with the fix. Regression for NousResearch#112096
Author
|
Duplicate of #112097, which was opened earlier for the same fix in |
16 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
In
plugins/plugin_loader.py::load_plugin_module, add the samesys.modulescleanup on failure for the sibling loop that already exists for the main module path (sys.modules.pop(full_sub_name, None)when_exec(sub_mod, ...)returns False).Why
_new_module()inserts the module intosys.modulesbefore execution;_exec()intentionally leaves the entry on failure ("callers needing a clean retry pop it themselves"), but the sibling loop is a caller that never retries — so a half-initialized module stayed cached. A later relative import of one of its names then raisedImportError: cannot import name ...(error.name == None, uncatchable asModuleNotFoundError) exactly where the plugin's own handler expectsModuleNotFoundError. Repro and code evidence in #112096.Fixes #112096
How to test
scripts/run_tests.sh tests/plugins/test_plugin_loader_sibling_cleanup.py -q— 4 tests:main, green here: failed sibling evicted fromsys.modulesmain, green here: laterimportlib.import_moduleraisesModuleNotFoundError, notImportErrorPlatforms tested
Linux (Ubuntu 22.04, Python 3.11). Change is platform-neutral module bookkeeping.
Notes
tests/plugins/files fail locally both with and without this change (pre-existing on this machine; likely side-dependent tests/optional deps) — not touched here.