Skip to content

Prepare for importlib.metadata 8 update #4035

@mpurnell1

Description

@mpurnell1

As of June 2024, progress was made towards fixing metadata values being None.

Finally, importlib_metadata 8 provides the desired behavior, raising KeyError on a missing key. If you want the KeyError behavior, depend on and use importlib_metadata 8 or later (to be incorporated in Python 3.14).

Originally posted by @jaraco in python/importlib_metadata#371

In preparation for this change, we should not get the attribute directly, but instead explicitly provide a default of None. Doing so would remove a DeprecationWarning, and the fix would be valid through Python 3.14, since providing a default value prevents a KeyError being raised.

I would be happy to submit a PR for this, but I don't quite understand the commit message formatting guidelines.

sentry_sdk/utils.py:1668 current
name = dist.metadata["Name"]

sentry_sdk/utils.py:1668 proposed
name = dist.metadata.get("Name", None)

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions