Skip to content

fix(redis): treat explicit db=None as database index 0#4828

Open
ahmed5145 wants to merge 2 commits into
open-telemetry:mainfrom
ahmed5145:fix/redis-db-none-1905
Open

fix(redis): treat explicit db=None as database index 0#4828
ahmed5145 wants to merge 2 commits into
open-telemetry:mainfrom
ahmed5145:fix/redis-db-none-1905

Conversation

@ahmed5145

Copy link
Copy Markdown

Description

RedisInstrumentor reads the database index from the connection's
connection_kwargs via conn_kwargs.get("db", 0). dict.get only falls
back to the default when the key is missing — if db is present and set to
None (which redis-py allows, e.g. Redis(..., db=None) or some from_url
paths), the value stays None. That None was then passed straight to the
database-index attribute, producing:

Invalid type NoneType for attribute 'db.redis.database_index' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types

This coerces an explicit db=None to 0 (Redis' default database), in both
_extract_conn_attributes and the pipeline span-name fallback in
_build_span_name, so no invalid attribute is emitted.

Fixes #1905

Type of change

Please delete options that are not relevant.

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

How Has This Been Tested?

  • Added test_attributes_db_none, which sets db=None in the client's
    connection kwargs and asserts the span reports db.redis.database_index == 0
    with no invalid-attribute warning.
  • Ran the redis instrumentation test suite locally (test_attributes_db_none
    and test_attributes_default pass).

Does This PR Require a Core Repo Change?

  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

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

@ahmed5145
ahmed5145 requested a review from a team as a code owner July 16, 2026 21:05
@github-project-automation github-project-automation Bot moved this to Approved PRs in Python PR digest Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved PRs

Development

Successfully merging this pull request may close these issues.

Redis instrumentation doesn't handle correctly connection info

2 participants