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%.
@@ -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)),
)
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'
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
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).
- 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.”
“Just wanted to open the same issue. Also this issue can be find in StrictRedis objects (same reason)”
“think i have the same problem: isn't it? Happens with redis==3.0.1”
Failure Signature (Search String)
- import redis
Error Message
Stack trace
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 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
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
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.
When NOT to Use This Fix
- This fix is not applicable if the repr method is overridden incorrectly.
Verify Fix
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
| Version | Status |
|---|---|
| 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.