-
Notifications
You must be signed in to change notification settings - Fork 623
[HOTFIX] Use importlib.util.find_spec for pluggable worker discovery #1918
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
base: v0.163.2-hotfix
Are you sure you want to change the base?
Changes from all commits
94bd763
52e342d
3179fb6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -323,27 +323,26 @@ def _verify_pluggable_worker_exists(worker_type: WorkerType) -> bool: | |||||||||||||||||||
|
|
||||||||||||||||||||
| try: | ||||||||||||||||||||
| import importlib | ||||||||||||||||||||
| from pathlib import Path | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Check if the worker.py file exists | ||||||||||||||||||||
| # Path resolution: builder.py is at /app/workers/shared/infrastructure/config/ | ||||||||||||||||||||
| # We need to get to /app/workers/, so go up 3 levels | ||||||||||||||||||||
| pluggable_worker_path = ( | ||||||||||||||||||||
| Path(__file__).resolve().parents[3] | ||||||||||||||||||||
| / "pluggable_worker" | ||||||||||||||||||||
| / worker_type.value | ||||||||||||||||||||
| / "worker.py" | ||||||||||||||||||||
| ) | ||||||||||||||||||||
| import importlib.util | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Ask Python's import system whether the module is resolvable. | ||||||||||||||||||||
| # find_spec() consults all registered finders and handles every | ||||||||||||||||||||
| # module representation (source .py, Nuitka/Cython .so, .pyc, | ||||||||||||||||||||
| # namespace packages, zipimports) — unlike a filesystem check | ||||||||||||||||||||
| # for a specific file extension, which breaks for compiled plugins. | ||||||||||||||||||||
| module_path = f"pluggable_worker.{worker_type.value}.worker" | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hope this not break running worker locally insated of docker
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tested locally — doesn't break local runs. Local runs go through Coverage comparison vs old code:
The only way someone could get a false negative from the new code but not the old is if they ran a pluggable worker outside Also confirmed on |
||||||||||||||||||||
|
|
||||||||||||||||||||
| if not pluggable_worker_path.exists(): | ||||||||||||||||||||
| logger.error(f"Pluggable worker file not found: {pluggable_worker_path}") | ||||||||||||||||||||
| if importlib.util.find_spec(module_path) is None: | ||||||||||||||||||||
|
greptile-apps[bot] marked this conversation as resolved.
|
||||||||||||||||||||
| logger.error(f"Pluggable worker module not importable: {module_path}") | ||||||||||||||||||||
| return False | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Try to import the module to verify it's valid | ||||||||||||||||||||
| module_path = f"pluggable_worker.{worker_type.value}.worker" | ||||||||||||||||||||
| # Load it to catch findable-but-broken modules (e.g. import errors | ||||||||||||||||||||
| # inside worker.py that find_spec wouldn't surface). | ||||||||||||||||||||
| importlib.import_module(module_path) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| except ImportError: | ||||||||||||||||||||
| except (ImportError, ValueError): | ||||||||||||||||||||
| # ValueError: find_spec raises this when sys.modules[module_path] is | ||||||||||||||||||||
| # populated but has __spec__ = None (from a prior failed import). | ||||||||||||||||||||
| logger.exception(f"Failed to import pluggable worker {worker_type.value}") | ||||||||||||||||||||
| return False | ||||||||||||||||||||
| except (OSError, AttributeError): | ||||||||||||||||||||
|
|
||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.