Jump to solution
Verify

The Fix

pip install redis==7.1.0

Based on closed redis/redis-py issue #995 · PR/commit linked

Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.

Jump to Verify Open PR/Commit
@@ -937,7 +937,7 @@ def __init__(self, connection_class=Connection, max_connections=None, return "%s<%s>" % ( type(self).__name__, - self.connection_class.description_format % self.connection_kwargs, + repr(self.connection_class(**self.connection_kwargs)), )
repro.py
import redis p = redis.ConnectionPool() repr(p) Traceback (most recent call last): File "<input>", line 1, in <module> File "venv/local/lib/python2.7/site-packages/redis/connection.py", line 939, in __repr__ self.connection_class.description_format % self.connection_kwargs, KeyError: 'host'
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Upgrade to fixed release\npip install redis==7.1.0\nWhen NOT to use: This fix is not applicable if the repr method is overridden incorrectly.\n\n

Why This Fix Works in Production

  • Trigger: import redis
  • Mechanism: KeyError occurs in the repr method due to missing host, port, or db in connection_kwargs
  • Why the fix works: Fixes a KeyError in the repr method of ConnectionPool when using default values. (first fixed release: 7.1.0).
Production impact:
  • If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.

Why This Breaks in Prod

  • Shows up under Python 2.7 in real deployments (not just unit tests).
  • KeyError occurs in the repr method due to missing host, port, or db in connection_kwargs
  • Surfaces as: import redis

Proof / Evidence

  • GitHub issue: #995
  • Fix PR: https://github.com/redis/redis-py/pull/1043
  • First fixed release: 7.1.0
  • Reproduced locally: No (not executed)
  • Last verified: 2026-02-09
  • Confidence: 0.85
  • Did this fix it?: Yes (upstream fix exists)
  • Own content ratio: 0.43

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“This issue also trouble me. Wish to be fix.”
@GitHubMota · 2018-08-06 · source
“Just wanted to open the same issue. Also this issue can be find in StrictRedis objects (same reason)”
@michaelDovgal · 2018-06-12 · source
“think i have the same problem: isn't it? Happens with redis==3.0.1”
@jedie · 2019-01-02 · source

Failure Signature (Search String)

  • import redis

Error Message

Stack trace
error.txt
Error Message ------------- import redis p = redis.ConnectionPool() repr(p) Traceback (most recent call last): File "<input>", line 1, in <module> File "venv/local/lib/python2.7/site-packages/redis/connection.py", line 939, in __repr__ self.connection_class.description_format % self.connection_kwargs, KeyError: 'host'
Stack trace
error.txt
Error Message ------------- def __repr__(self): return "%s<%s>" % ( type(self).__name__, self.connection_class.description_format % self.connection_kwargs, ) E KeyError: 'db' self = <[KeyError("'db'") raised in repr()] ConnectionPool object at 0x7fa4f78192b0> /usr/local/lib/python3.6/site-packages/redis/connection.py:944: KeyError

Minimal Reproduction

repro.py
import redis p = redis.ConnectionPool() repr(p) Traceback (most recent call last): File "<input>", line 1, in <module> File "venv/local/lib/python2.7/site-packages/redis/connection.py", line 939, in __repr__ self.connection_class.description_format % self.connection_kwargs, KeyError: 'host'

Environment

  • Python: 2.7

What Broke

Calling repr on ConnectionPool without required arguments leads to application crashes.

Why It Broke

KeyError occurs in the repr method due to missing host, port, or db in connection_kwargs

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

pip install redis==7.1.0

When NOT to use: This fix is not applicable if the repr method is overridden incorrectly.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Fix reference: https://github.com/redis/redis-py/pull/1043

First fixed release: 7.1.0

Last verified: 2026-02-09. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix is not applicable if the repr method is overridden incorrectly.

Verify Fix

verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.

Did This Fix Work in Your Case?

Quick signal helps us prioritize which fixes to verify and improve.

Prevention

  • Track RSS + object counts after deployments; alert on monotonic growth and GC pressure.
  • Add a long-running test that repeats the failing call path and asserts stable memory.

Version Compatibility Table

VersionStatus
7.1.0 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.