Repository navigation
Fix orphaned namespace children purged by DependencyManager - #1956
Open
Allen (Allen5288) wants to merge 3 commits into
Open
Allen (Allen5288) wants to merge 3 commits into
Allen (Allen5288) wants to merge 3 commits into
Conversation
Implement orphan module removal after cache purge.
Fix missing newline at end of file in test_utilities_dependency.py
Allen (Allen5288)
requested review from
Gavin Aguiar (gavin-aguiar),
hallvictoria and
Varad Meru (vrdmr)
as code owners
November 24, 2026 23:02
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
This branch has not been deployed
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.
Fixes #1906
Summary
DependencyManager._remove_module_cache()purged thegooglenamespace package but left the regular subpackagegoogle.protobufcached, because a namespace package's__path__is dynamic (_NamespacePathre-computes against the just-mutatedsys.path) while a regular package has a static__file__. A laterimport google.protobufthen took thesys.modulesfast path without re-binding the child onto a fresh parent, sogoogle.protobuf.__version__raisedAttributeErrorand any function importing a Google Cloud client failed to load.The purge now also evicts modules orphaned by it: any remaining module whose parent package was evicted by this purge (or was already absent) is evicted too, to a fixpoint, so it is re-imported and re-bound from the current
sys.pathon next use. The fix is generic — no package is special-cased. Builtin andazure_functions_workermodules are still never evicted, and deliberately aliased modules (whose__name__differs from theirsys.moduleskey) are left alone.How did you test this change?
DependencyManager.prioritize_customer_dependencies(): before the fixgoogle.protobuf.__version__raisedAttributeErrorandimport google.api_corefailed; after the fix both succeed with version4.25.5.workers/tests/unittests/test_utilities_dependency.py(direct purge, end-to-end prioritize, unrelated-path guard, pre-existing-orphan repair).test_utilities_dependency.py: 51 passed, 1 skipped. With only the source change stashed, 3 of the 4 new tests fail.flake8clean. E2E tests need Core Tools + host and must run in CI.Note:
workers/proxy_worker/utils/dependency.pycarries the same purge logic and the same flaw; it is intentionally left out of this PR and can follow the same fix.Pull Request Checklist
Host-Worker Contract
Worker Execution Logic
If yes, please answer the following:
Python Version Coverage
azure_functions_workeris changed in this PR.proxy_workercarries the same purge logic and the same flaw and is intentionally left out to follow with the same fix (see the note above).Programming Model Compatibility (proxy_worker and r2p2)
proxy_workerorr2p2; the fix is confined toazure_functions_worker.