From 458f8570e8401640f449405379a75a0ba3c48cea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Tue, 25 Nov 2025 12:38:55 +0100 Subject: [PATCH 1/2] Fix KeyError: 'name' in python/extractor/imp.py on Python 3.14 Follow-up to https://github.com/github/codeql/pull/20630 The fix didn't fully work since when we raise the ImportError in `find_module` we don't pass a named argument into the format string which causes a `KeyError`. We need to use a format string without named arguments, like Python 3.13 and earlier did. --- python/extractor/imp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/extractor/imp.py b/python/extractor/imp.py index 8d703250b671..5130f64ebef1 100644 --- a/python/extractor/imp.py +++ b/python/extractor/imp.py @@ -25,7 +25,7 @@ from importlib._bootstrap import _ERR_MSG except ImportError: from importlib._bootstrap import _ERR_MSG_PREFIX - _ERR_MSG = _ERR_MSG_PREFIX + '{name!r}' + _ERR_MSG = _ERR_MSG_PREFIX + '{!r}' from importlib import machinery from importlib import util From f55ff96674b4ffa499334af941ebb24f359b29db Mon Sep 17 00:00:00 2001 From: Taus Date: Thu, 27 Nov 2025 13:52:37 +0000 Subject: [PATCH 2/2] Python: Bump extractor version and add change note --- python/extractor/semmle/util.py | 2 +- .../change-notes/2025-11-27-fix-keyerror-in-imp-module.md | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 python/ql/lib/change-notes/2025-11-27-fix-keyerror-in-imp-module.md diff --git a/python/extractor/semmle/util.py b/python/extractor/semmle/util.py index 2f6a18ac7a97..445d40dab3d0 100644 --- a/python/extractor/semmle/util.py +++ b/python/extractor/semmle/util.py @@ -10,7 +10,7 @@ #Semantic version of extractor. #Update this if any changes are made -VERSION = "7.1.5" +VERSION = "7.1.6" PY_EXTENSIONS = ".py", ".pyw" diff --git a/python/ql/lib/change-notes/2025-11-27-fix-keyerror-in-imp-module.md b/python/ql/lib/change-notes/2025-11-27-fix-keyerror-in-imp-module.md new file mode 100644 index 000000000000..8494331ef3b4 --- /dev/null +++ b/python/ql/lib/change-notes/2025-11-27-fix-keyerror-in-imp-module.md @@ -0,0 +1,5 @@ +--- +category: fix +--- + +- Fixed a bug in the Python extractor's import handling where failing to find an import in `find_module` would cause a `KeyError` to be raised. (Contributed by @akoeplinger.)