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
- Pass driver_info=None and use the lib_name/lib_version string kwargs instead for simple cases.
- Build a DriverInfo instance and pass that: driver_info=DriverInfo(...).add_upstream_driver(...).
- If your config holds a dict, convert it to a DriverInfo explicitly before constructing the client.
- 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
- Use lib_name/lib_version string kwargs for simple cases instead of driver_info.
- If your config holds a dict, convert it to a DriverInfo explicitly at the boundary.
- Type-check driver_info at construction to surface the error early.
- Do not pass strings, dicts, or tuples as driver_info.
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
- {field_name} must not contain spaces, newlines, non-printabl
- Upstream driver name must use a Python package-style name: s
- Driver name must not be None
- Driver version must not be None
- Subcommand {subcommand_name} not found in command {command_n
AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04).
Data as JSON: /data/errors/2995aa591c3400a5.json.
Report an issue: GitHub.