{"id":"2995aa591c3400a5","repo":"redis/redis-py","slug":"driver-info-must-be-a-driverinfo-instance-or-none","errorCode":null,"errorMessage":"driver_info must be a DriverInfo instance or None","messagePattern":"driver_info must be a DriverInfo instance or None","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"redis/driver_info.py","lineNumber":184,"sourceCode":"    lib_name : str, optional\n        The library name (default: \"redis-py\")\n    lib_version : str, optional\n        The library version (default: auto-detected)\n\n    Returns\n    -------\n    DriverInfo, optional\n        The resolved DriverInfo instance\n    \"\"\"\n    if driver_info is SENTINEL:\n        if lib_name is None and lib_version is None:\n            return None\n        return DriverInfo(name=lib_name, lib_version=lib_version)\n\n    if driver_info is None or isinstance(driver_info, DriverInfo):\n        return driver_info\n\n    raise TypeError(\"driver_info must be a DriverInfo instance or None\")\n","sourceCodeStart":166,"sourceCodeEnd":185,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/driver_info.py#L166-L185","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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)."],"exampleFix":"// before\nr = redis.Redis(driver_info={'name': 'my-driver', 'version': '1.0'})\n\n// after\nr = redis.Redis(driver_info=DriverInfo().add_upstream_driver('my-driver', '1.0'))","handlingStrategy":"type-guard","validationCode":"from redis.driver_info import DriverInfo\ndi = config.get('driver_info')\nif di is not None and not isinstance(di, DriverInfo):\n    raise TypeError('driver_info must be DriverInfo or None')\nr = redis.Redis(driver_info=di)","typeGuard":"from redis.driver_info import DriverInfo\ndef is_driver_info_or_none(v) -> bool:\n    return v is None or isinstance(v, DriverInfo)","tryCatchPattern":null,"preventionTips":["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."],"tags":["driver-info","validation","typeerror","client-config"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}