Skip to content

Conversation

@tejaspavanb
Copy link

@tejaspavanb tejaspavanb commented Jan 10, 2026

Description

Fixes #4821

Summary

On Python 3.9, passing an invalid AnyValue type could raise an unexpected AttributeError
while constructing the error message, due to certain typing types missing a __name__
attribute.

Motivation and Context

This change ensures that error messages are constructed safely by resolving type names
using a fallback mechanism. It restores the expected TypeError behavior without altering
existing functionality. The fix follows the approach suggested in the issue discussion
and adds a regression test to cover this edge case.


Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Unit tests

Test details

  • Ran python -m pytest opentelemetry-api/tests/attributes
  • Added a regression test to verify that a TypeError is raised only when stringification of an invalid value fails
  • Verified all existing attribute tests pass on Windows with Python 3.12

Does This PR Require a Contrib Repo Change?

  • Yes. – Link to PR:
  • No.

Checklist

  • Followed the style guidelines of this project
  • Changelogs have been updated (not required for this fix)
  • Unit tests have been added
  • Documentation has been updated (not required)

@tejaspavanb tejaspavanb requested a review from a team as a code owner January 10, 2026 14:05
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jan 10, 2026

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: tejaspavanb / name: Tejas Pavan B (c3361b2)

@tejaspavanb tejaspavanb changed the title Fix incorrect AttributeError for invalid AnyValue types (#4826) Fix incorrect AttributeError for invalid AnyValue types (#4821) Jan 12, 2026
Copy link
Contributor

@xrmx xrmx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that 3.9 is deprecated since november and since the report of the issue we've already changed the code to reduce greatly the time this code is called in practice if we really want to merge this, we need to add a comment with a TODO for go back to plain __name__ after we drop 3.9 support in May.

@xrmx xrmx moved this to Easy to review / merge / close in @xrmx's Python PR digest Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Easy to review / merge / close

Development

Successfully merging this pull request may close these issues.

Incorrect error when passing wrong attribute type on Python 3.9

2 participants