Skip to content

Fix AttributeError when invalid type passed to attributes on Python 3.9#5018

Closed
pkb94 wants to merge 2 commits intoopen-telemetry:mainfrom
pkb94:fix/4821-attribute-error-python39
Closed

Fix AttributeError when invalid type passed to attributes on Python 3.9#5018
pkb94 wants to merge 2 commits intoopen-telemetry:mainfrom
pkb94:fix/4821-attribute-error-python39

Conversation

@pkb94
Copy link
Copy Markdown

@pkb94 pkb94 commented Mar 28, 2026

On Python 3.9, typing generics like Mapping and Sequence lack name, causing AttributeError instead of TypeError when an invalid type is passed to _clean_extended_attribute_value. Use getattr with fallback to _name to safely handle these types.

Fixes #4821

Description

Fixes #4821

Bug Fix

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Added test test_invalid_type_raises_type_error_not_attribute_error in
opentelemetry-api/tests/attributes/test_attributes.py.

The test passes an object whose __str__ raises an exception to
_clean_extended_attribute_value and asserts that a TypeError is raised
(not AttributeError) with the expected message content.

Run with:
python3 -m tox -e py39-test-opentelemetry-api -- opentelemetry-api/tests/attributes/test_attributes.py

Does This PR Require a Contrib Repo Change?

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

pkb94 added 2 commits March 28, 2026 09:29
On Python 3.9, typing generics like Mapping and Sequence lack __name__,
causing AttributeError instead of TypeError when an invalid type is passed
to _clean_extended_attribute_value. Use getattr with fallback to _name
to safely handle these types.

Fixes open-telemetry#4821

Signed-off-by: Pooja Kittanakere Balaji <pk73@njit.edu>
Signed-off-by: Pooja Kittanakere Balaji <pk73@njit.edu>
@pkb94 pkb94 requested a review from a team as a code owner March 28, 2026 13:54
@linux-foundation-easycla
Copy link
Copy Markdown

CLA Not Signed

@xrmx
Copy link
Copy Markdown
Contributor

xrmx commented Mar 30, 2026

Closing as duplicate of #4876

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

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Incorrect error when passing wrong attribute type on Python 3.9

2 participants