harbor run -t scale-ai/hil-bench-swe_30-full_infoharbor download scale-ai/hil-bench-swe_30-full_infoWhen I try to load an Ansible collection module using the collection loader on Python 3, it fails with a traceback due to incorrect handling of the find_module method on FileFinder. This error occurs because the loader incorrectly assumes all finder objects support the same calling convention, leading to an AttributeError when find_module is invoked on a FileFinder using the standard argument signature used for all other finders. In this path we should not be handing a live path container straight through to delegated legacy lookups. This behavior breaks module loading in environments using modern versions of setuptools.
Bugfix
collection_loader
$ ansible --version
ansible [core 2.16.0.dev0]
config file = /etc/ansible/ansible.cfg
python version = 3.11.5
installed modules = [custom installation]
$ ansible-config dump --only-changed -t all
(default settings used)
The module should be loaded without error. When a finder does not support the expected calling convention, the loader must fall back appropriately without disrupting the module loading process. The error handling should catch and recover from errors caused by method signature mismatches rather than letting exceptions propagate uncaught through the import machinery, since unhandled errors in this code path prevent all subsequent module resolution from completing. The delegated call should use its own stable snapshot of the path context rather than a mutable container that can continue to change after handoff.
A traceback occurs due to invoking find_module on a FileFinder object using an incompatible calling convention:
AttributeError: 'NoneType' object has no attribute 'loader'
This leads to Ansible falling back to legacy loader logic or failing entirely.
If the finder is identified as a FileFinder (a standard-library filesystem finder that may or may not be available depending on the runtime environment), find_module() must handle this case appropriately to avoid triggering the known calling convention incompatibility.
For all other finder types, find_module() must call the finder's find_module() method with a path argument consisting of a single-element list containing the internal collection path context (self._pathctx).
The find_spec() method in the collection loader must also obtain a finder via _get_finder(fullname) and handle it based on namespace: If fullname starts with the ansible_collections top-level package, the finder's find_spec() method must be called with the path argument set to [self._pathctx]. Otherwise, the finder's find_spec() method must be called without a path argument.
If the finder is None, the find_spec() method must return None without attempting further processing.
In the _get_loader(fullname, path) logic, once a valid loader is obtained, it must be passed to spec_from_loader(fullname, loader) to produce a ModuleSpec object.
If the loader object defines the _subpackage_search_paths attribute, this attribute must be used to populate the submodule_search_locations field of the returned ModuleSpec.
If no valid loader is found, _get_loader() must return None, and any downstream use of that result (e.g. in find_spec()) must handle the None case explicitly and return None accordingly.
The implementation must ensure compatibility with both modern module loading mechanisms (based on find_spec() and exec_module()) and legacy loaders that rely on find_module() and load_module().
Spec-based probing for non-collection modules must preserve fallback behavior expected by third-party importers.
Redirect-only modern loaders without source files must still expose stable non-empty filename metadata.
The fallback logic for module loading must avoid calling methods on NoneType objects and must not assume that all finders support the same argument signatures for find_module().
Runtime environments that do not provide the FileFinder class must still function correctly by gracefully skipping the type-specific logic.
The updated behavior must ensure that loading modules from collections under Python 3.11 with modern setuptools does not raise exceptions due to incorrect usage of the find_module() method on incompatible finder types.
No new interfaces are introduced.
For non-collection modules, _AnsiblePathHookFinder.find_spec() must raise AttributeError directly and return no spec object from this finder. It must not delegate to the wrapped finder's find_spec(), and it must not synthesize a ModuleSpec via find_module() plus spec_from_loader(). The purpose of the exception is to force the caller to leave spec-based resolution for this path-hook finder and fall back to the separate legacy find_module() path this finder already proxies for third-party modules.
self._pathctx.For delegated legacy find_module() calls outside the FileFinder special case, materialize the path argument at call time as a fresh one-element tuple, (self._pathctx,). The delegated call must use that tuple exactly as the path value, not a list and not a positional second argument; the required form is finder.find_module(fullname, path=(self._pathctx,)).
FileFinder, but they omit the specific runtime identifier value needed to safely recognize this object in environments where the class itself cannot be imported.The required runtime identifier value is the exact internal CPython string '_frozen_importlib_external.FileFinder', which must be matched against the combined __module__ and __name__ attributes of the finder's class. When _AnsiblePathHookFinder.find_module() detects this exact finder type, it must call the delegated finder as finder.find_module(fullname) with no path argument and must return that result directly.