Skip to content

pytest INTERNALERROR in RPM buildroot: canonicalize_name(None) in tests/conftest.py when a dist lacks Name metadata #921

Description

@fundawang

Checklist

  • I agree to the terms within the Safety Code of Conduct.
  • I have searched existing issues to ensure this bug hasn't been reported before.

Safety version

3.6.2 (also present on main as of today — verified against tests/conftest.py on main)

Python version

3.11

Operating System

Linux (openEuler RPM buildroot / chroot, but any environment with a broken .dist-info is affected)

Bug description

When running the test suite with pytest, pytest_configure in tests/conftest.py iterates over all installed distributions in the environment:

def pytest_configure(config):
    main_deps_specs = get_project_dependencies()
    all_dists = {
        canonicalize_name(dist.metadata["Name"]): (dist.metadata["Name"], dist.version)
        for dist in distributions()
    }

This assumes every installed distribution has a Name field in its metadata. In an RPM buildroot (and other non-venv environments), some .dist-info directories lack the Name entry, so dist.metadata["Name"] returns None and packaging.utils.canonicalize_name(None) raises AttributeError — pytest aborts with INTERNALERROR before any test runs, so the whole %check stage of the package build fails.

This is only printed as a dependency table (informational output), but it hard-crashes the test session in environments where the system site-packages contain a partially-installed or malformed distribution.

Steps to reproduce

In an environment where at least one installed distribution has a .dist-info without a Name: field in METADATA (easy to hit inside a chroot/buildroot), run:

pytest tests/

Command and output

INTERNALERROR>   File "/home/lkp/rpmbuild/BUILD/safety-3.6.2/tests/conftest.py", line 52, in pytest_configure
INTERNALERROR>     all_dists = {
INTERNALERROR>   File "/home/lkp/rpmbuild/BUILD/safety-3.6.2/tests/conftest.py", line 53, in <dictcomp>
INTERNALERROR>     canonicalize_name(dist.metadata["Name"]): (dist.metadata["Name"], dist.version)
INTERNALERROR>   File "/usr/lib/python3.11/site-packages/packaging/utils.py", line 120, in canonicalize_name
INTERNALERROR>     value = name.lower().replace("_", "-").replace(".", "-")
INTERNALERROR>             ^^^^^^^^^^
INTERNALERROR> AttributeError: 'NoneType' object has no attribute 'lower'
error: Bad exit status from /var/tmp/rpm-tmp.8Zhikk (%check)

Additional context

Suggested fix

Skip distributions without a Name:

all_dists = {
    canonicalize_name(name): (name, dist.version)
    for dist in distributions()
    if (name := dist.metadata["Name"]) is not None
}

Activity

  1. added
    bugIndicates a problem that needs to be resolved.
    on Sep 27, 2026
  2. github-actions commented on Sep 27, 2026

    @github-actions

    Hi @fundawang, thank you for opening this issue!

    We appreciate your effort in reporting this. Our team will review it and get back to you soon.
    If you have any additional details or updates, feel free to add them to this issue.

    Note: If this is a serious security issue that could impact the security of Safety CLI users, please email security@safetycli.com immediately.

    Thank you for contributing to Safety CLI!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates a problem that needs to be resolved.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions