redis/redis-py · error · TypeError

driver_info must be a DriverInfo instance or None

Error message

driver_info must be a DriverInfo instance or None

What it means

Raised as TypeError by resolve_driver_info (redis/driver_info.py:184). The Redis client's driver_info parameter accepts only a DriverInfo instance or None; passing any other type (a dict, a string, a tuple) cannot be resolved into driver metadata and is rejected so the error surfaces at construction rather than at connection time.

Source

Thrown at redis/driver_info.py:184

    lib_name : str, optional
        The library name (default: "redis-py")
    lib_version : str, optional
        The library version (default: auto-detected)

    Returns
    -------
    DriverInfo, optional
        The resolved DriverInfo instance
    """
    if driver_info is SENTINEL:
        if lib_name is None and lib_version is None:
            return None
        return DriverInfo(name=lib_name, lib_version=lib_version)

    if driver_info is None or isinstance(driver_info, DriverInfo):
        return driver_info

    raise TypeError("driver_info must be a DriverInfo instance or None")

View on GitHub (pinned to da03cdc7e8)

Solutions

  1. Pass driver_info=None and use the lib_name/lib_version string kwargs instead for simple cases.
  2. Build a DriverInfo instance and pass that: driver_info=DriverInfo(...).add_upstream_driver(...).
  3. If your config holds a dict, convert it to a DriverInfo explicitly before constructing the client.
  4. Type-check at the boundary: assert driver_info is None or isinstance(driver_info, DriverInfo).

Example fix

// before
r = redis.Redis(driver_info={'name': 'my-driver', 'version': '1.0'})

// after
r = redis.Redis(driver_info=DriverInfo().add_upstream_driver('my-driver', '1.0'))
Defensive patterns

Strategy: type-guard

Validate before calling

from redis.driver_info import DriverInfo
di = config.get('driver_info')
if di is not None and not isinstance(di, DriverInfo):
    raise TypeError('driver_info must be DriverInfo or None')
r = redis.Redis(driver_info=di)

Type guard

from redis.driver_info import DriverInfo
def is_driver_info_or_none(v) -> bool:
    return v is None or isinstance(v, DriverInfo)

Prevention

When it happens

Trigger: Constructing redis.Redis(..., driver_info=<dict|str|tuple>) or calling resolve_driver_info() directly with a value that is neither None nor a DriverInfo instance.

Common situations: Passing a dict {'name':...,'version':...} expecting it to be coerced; passing a string version; a config parser returning an arbitrary object; confusion between lib_name/lib_version (strings) and driver_info (the typed object).

Related errors


AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04). Data as JSON: /data/errors/2995aa591c3400a5.json. Report an issue: GitHub.