pylint-django
pylint-django copied to clipboard
pylint-django calls ast_from_module_name without catching AstroidImportError
Bug description
Possibly related to: https://github.com/pylint-dev/pylint/issues/8554
Pylint consistently crashes across all versions including latest, on one particular file, throwing 'AstroidError' mentioning 'inference_tip.py' and '_inference_tip_cached'.
Configuration
No response
Command used
pylint <directory>
Pylint output
I'm finding out if I'm allowed to post the actual code.
The error is:
pylint crashed with a ``AstroidError`` and with the following stacktrace:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/astroid/inference_tip.py", line 33, in _inference_tip_cached
result = _cache[func, node]
KeyError: (<function infer_key_classes at 0x7ff9268d2c20>, <Call l.20 at 0x7ff921fd10f0>)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/pylint/checkers/utils.py", line 1371, in safe_infer
value = next(infer_gen)
File "/usr/local/lib/python3.10/site-packages/astroid/nodes/node_ng.py", line 171, in infer
yield from self._infer(context=context, **kwargs)
File "/usr/local/lib/python3.10/site-packages/astroid/decorators.py", line 143, in raise_if_nothing_inferred
yield next(generator)
File "/usr/local/lib/python3.10/site-packages/astroid/decorators.py", line 112, in wrapped
for res in _func(node, context, **kwargs):
File "/usr/local/lib/python3.10/site-packages/astroid/bases.py", line 177, in _infer_stmts
for inf in stmt.infer(context=context):
File "/usr/local/lib/python3.10/site-packages/astroid/nodes/node_ng.py", line 161, in infer
results = list(self._explicit_inference(self, context, **kwargs))
File "/usr/local/lib/python3.10/site-packages/astroid/inference_tip.py", line 40, in _inference_tip_cached
result = _cache[func, node] = list(func(*args, **kwargs))
File "/usr/local/lib/python3.10/site-packages/pylint_django/transforms/foreignkey.py", line 120, in infer_key_classes
MANAGER.ast_from_module_name(module_name)
File "/usr/local/lib/python3.10/site-packages/astroid/manager.py", line 239, in ast_from_module_name
raise e
File "/usr/local/lib/python3.10/site-packages/astroid/manager.py", line 184, in ast_from_module_name
found_spec = self.file_from_module_name(modname, context_file)
File "/usr/local/lib/python3.10/site-packages/astroid/manager.py", line 292, in file_from_module_name
raise value.with_traceback(None) # pylint: disable=no-member
astroid.exceptions.AstroidImportError: Failed to import module projects.models with error:
No module named projects.models.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 811, in _lint_file
check_astroid_module(module)
File "/usr/local/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 1085, in check_astroid_module
retval = self._check_astroid_module(
File "/usr/local/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 1135, in _check_astroid_module
walker.walk(node)
File "/usr/local/lib/python3.10/site-packages/pylint/utils/ast_walker.py", line 94, in walk
self.walk(child)
File "/usr/local/lib/python3.10/site-packages/pylint/utils/ast_walker.py", line 91, in walk
callback(astroid)
File "/usr/local/lib/python3.10/site-packages/pylint_plugin_utils/__init__.py", line 58, in __call__
self.augmentation_func(Chain(self.old_method, node), node)
File "/usr/local/lib/python3.10/site-packages/pylint_plugin_utils/__init__.py", line 115, in __call__
chain()
File "/usr/local/lib/python3.10/site-packages/pylint_plugin_utils/__init__.py", line 67, in __call__
self.old_method(self.node)
File "/usr/local/lib/python3.10/site-packages/pylint_plugin_utils/__init__.py", line 58, in __call__
self.augmentation_func(Chain(self.old_method, node), node)
File "/usr/local/lib/python3.10/site-packages/pylint_plugin_utils/__init__.py", line 115, in __call__
chain()
File "/usr/local/lib/python3.10/site-packages/pylint_plugin_utils/__init__.py", line 67, in __call__
self.old_method(self.node)
File "/usr/local/lib/python3.10/site-packages/pylint_plugin_utils/__init__.py", line 58, in __call__
self.augmentation_func(Chain(self.old_method, node), node)
File "/usr/local/lib/python3.10/site-packages/pylint_plugin_utils/__init__.py", line 115, in __call__
chain()
File "/usr/local/lib/python3.10/site-packages/pylint_plugin_utils/__init__.py", line 67, in __call__
self.old_method(self.node)
File "/usr/local/lib/python3.10/site-packages/pylint_plugin_utils/__init__.py", line 58, in __call__
self.augmentation_func(Chain(self.old_method, node), node)
File "/usr/local/lib/python3.10/site-packages/pylint_plugin_utils/__init__.py", line 115, in __call__
chain()
File "/usr/local/lib/python3.10/site-packages/pylint_plugin_utils/__init__.py", line 67, in __call__
self.old_method(self.node)
File "/usr/local/lib/python3.10/site-packages/pylint/checkers/classes/class_checker.py", line 876, in visit_classdef
self._check_bases_classes(node)
File "/usr/local/lib/python3.10/site-packages/pylint/checkers/classes/class_checker.py", line 2096, in _check_bases_classes
unimplemented_abstract_methods(node, is_abstract).items(),
File "/usr/local/lib/python3.10/site-packages/pylint/checkers/utils.py", line 972, in unimplemented_abstract_methods
inferred = safe_infer(obj)
File "/usr/local/lib/python3.10/site-packages/pylint/checkers/utils.py", line 1375, in safe_infer
raise AstroidError from e
astroid.exceptions.AstroidError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 775, in _lint_files
self._lint_file(fileitem, module, check_astroid_module)
File "/usr/local/lib/python3.10/site-packages/pylint/lint/pylinter.py", line 813, in _lint_file
raise astroid.AstroidError from e
astroid.exceptions.AstroidError
Expected behavior
Pylint would just warn about code findings and not crash.
Pylint version
pylint 2.17.4 (got same result in 2.17.5 which I now don't seem to be able to install) astroid 2.15.5 Python 3.10.11 (main, May 23 2023, 13:58:30) [GCC 10.2.1 20210110]
OS / Environment
Docker Debian GNU/Linux 11
Additional dependencies
No response