Skip to content

importlib.metadata.entry_points(group=...) raises for every group on 3.15 when any distribution has a malformed entry point #163118

Todo

Description

@sethfitz

Bug report

On Python 3.15, one installed distribution with a malformed entry-point value makes importlib.metadata.entry_points(group=...) raise ValueError for every group, including groups the malformed entry is not in. On 3.14 the same environment works.

EntryPoint.__init__ on the 3.15 branch evaluates self.module, so constructing the entry point validates its value. entry_points() constructs every entry point of every distribution before selecting by group, so the first invalid value anywhere aborts the selection.

Reproduction (3.15.2, a venv with only pydantic 2.14.4 installed, run with -I):

python3.15 -m venv v && v/bin/pip install pydantic
SP=$(v/bin/python -c "import sysconfig; print(sysconfig.get_paths()['purelib'])")
mkdir "$SP/badep-0.1.dist-info"
printf 'Metadata-Version: 2.1\nName: badep\nVersion: 0.1\n' > "$SP/badep-0.1.dist-info/METADATA"
printf '[console_scripts]\nbad = !!\n' > "$SP/badep-0.1.dist-info/entry_points.txt"
v/bin/python -I -c "from pydantic import BaseModel
class M(BaseModel):
    x: int"

Output ends:

  File ".../pydantic/plugin/_loader.py", line 40, in get_plugins
  File ".../lib/python3.15/importlib/metadata/__init__.py", line 1125, in entry_points
  ...
  File ".../lib/python3.15/importlib/metadata/__init__.py", line 243, in _match
    raise ValueError(
ValueError: ('Invalid object reference. See https://packaging.python.org/en/latest/specifications/entry-points/#data-model', '!!')

pydantic asks only for the pydantic group; the malformed entry is in console_scripts. With the same badep dist-info on 3.14, the script runs. So does 3.15 with PYDANTIC_DISABLE_PLUGINS=1, which skips the entry_points call.

importlib_metadata restored lazy validation in python/importlib_metadata#523, "so one malformed entry point no longer prevents entry points in other groups from being selected" (its changelog). That change is on main through gh-160386 / GH-160387 (the 3.16 sync, 5a97efe766), whose EntryPoint.__init__ no longer touches self.module. The 3.15 branch still has the eager call. Since 3.15 is released and 3.14 did not fail this way, I'd ask for the lazy-validation part to be backported to 3.15 as a bug fix, separately from the rest of the 3.16 sync.

CPython versions tested on

3.15, 3.14 (control)

Operating systems tested on

Linux

Linked PRs

Activity

  1. added
    type-bug
    stdlib
    on Dec 4, 2026
  2. sreevx commented on Dec 4, 2026

    @sreevx

    I’m interested in contributing a targeted backport of the lazy-validation behavior to the 3.15 branch, with regression tests covering the unrelated malformed entry-point case. Would the maintainers consider this an appropriate 3.15 bug-fix contribution, or is there a reason to leave the branch unchanged?

  3. picnixz commented on Dec 5, 2026

    @picnixz
    Member

    @jaraco , I'm assigning this so that you can decide what to do for 3.15 (I believe you can make the backport but not sure if you have something else in mind)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

stdlibtopic-importlibtype-bug

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions