The Fix
pip install redis==7.1.0
Based on closed redis/redis-py issue #2581 · 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%.
@@ -1153,6 +1153,7 @@ def __init__(
redis_connect_func=None,
credential_provider: Optional[CredentialProvider] = None,
+ command_packer=None,
):
"""
class Connection:
def __init__(self, ...):
...
self._command_packer = self._construct_command_packer(command_packer)
class SSLConnection(Connection):
def __init__(self, ...):
...
super().__init__(...)
class UnixDomainSocketConnection(Connection):
def __init__(self, ...):
# does not call _construct_command_packer nor super().__init__()
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 should not be applied if the connection logic is fundamentally altered or if using a different connection type.\n\n
Why This Fix Works in Production
- Trigger: redis_conn.ping()
- Mechanism: This fix addresses the AttributeError in UnixDomainSocketConnection by ensuring the _command_packer is properly initialized.
- Why the fix works: This fix addresses the AttributeError in UnixDomainSocketConnection by ensuring the _command_packer is properly initialized. (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 3.9 in real deployments (not just unit tests).
- Surfaces as: Traceback (most recent call last):
Proof / Evidence
- GitHub issue: #2581
- Fix PR: https://github.com/redis/redis-py/pull/2583
- Fix commit: https://github.com/redis/redis-py/commit/2b470cb76534eca04e181e1877a0674032f7e82a
- First fixed release: 7.1.0
- Reproduced locally: No (not executed)
- Last verified: 2026-02-07
- Confidence: 0.75
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.47
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Looks like there is no synchronous tests that run any command on SSLConnection/UnixDomainSocketConnection.”
“also seeing this in our apps, had to pin to 4.4.2 to prevent our django app from crashing anytime it attempted to use the cache”
“Seems like the bug was introduced just before the 4.5.0 release: https://github.com/redis/redis-py/pull/2570 @prokazov Could you take a look please? Strange that this does not get…”
“Actually SSLConnection does call super().__init__ so that one should be fine.”
Failure Signature (Search String)
- redis_conn.ping()
Error Message
Stack trace
Error Message
-------------
Traceback (most recent call last):
File "<redacted>", line 142, in main
redis_conn.ping()
File "/usr/local/lib/python3.9/dist-packages/redis/commands/core.py", line 1194, in ping
return self.execute_command("PING", **kwargs)
File "/usr/local/lib/python3.9/dist-packages/redis/client.py", line 1258, in execute_command
return conn.retry.call_with_retry(
File "/usr/local/lib/python3.9/dist-packages/redis/retry.py", line 46, in call_with_retry
return do()
File "/usr/local/lib/python3.9/dist-packages/redis/client.py", line 1259, in <lambda>
lambda: self._send_command_parse_response(
File "/usr/local/lib/python3.9/dist-packages/redis/client.py", line 1234, in _send_command_parse_response
conn.send_command(*args)
File "/usr/local/lib/python3.9/dist-packages/redis/connection.py", line 916, in send_command
self._command_packer.pack(*args),
AttributeError: 'UnixDomainSocketConnection' object has no attribute '_command_packer'
Minimal Reproduction
class Connection:
def __init__(self, ...):
...
self._command_packer = self._construct_command_packer(command_packer)
class SSLConnection(Connection):
def __init__(self, ...):
...
super().__init__(...)
class UnixDomainSocketConnection(Connection):
def __init__(self, ...):
# does not call _construct_command_packer nor super().__init__()
Environment
- Python: 3.9
What Broke
The application crashes with an AttributeError when attempting to ping the Redis server.
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.
Option D — Guard side-effects with OnceOnly Guardrail for side-effects
Mitigate duplicate external side-effects under retries/timeouts/agent loops by gating the operation before calling external systems.
- Place OnceOnly between your code/agent and real side-effects (Stripe, emails, CRM, APIs).
- Use a stable key per side-effect (e.g., customer_id + action + idempotency_key).
- Fail-safe: configure fail-open vs fail-closed based on blast radius and spend risk.
Show example snippet (optional)
from onceonly import OnceOnly
import os
once = OnceOnly(api_key=os.environ["ONCEONLY_API_KEY"], fail_open=True)
# Stable idempotency key per real side-effect.
# Use a request id / job id / webhook delivery id / Stripe event id, etc.
event_id = "evt_..." # replace
key = f"stripe:webhook:{event_id}"
res = once.check_lock(key=key, ttl=3600)
if res.duplicate:
return {"status": "already_processed"}
# Safe to execute the side-effect exactly once.
handle_event(event_id)
Fix reference: https://github.com/redis/redis-py/pull/2583
First fixed release: 7.1.0
Last verified: 2026-02-07. Validate in your environment.
When NOT to Use This Fix
- This fix should not be applied if the connection logic is fundamentally altered or if using a different connection type.
- Do not use this to hide logic bugs or data corruption. Use it to block duplicate external side-effects and enforce tool permissions/spend caps.
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
- Add a TLS smoke test that performs a real handshake in CI (include CA bundle validation and hostname checks).
- Alert on handshake failures by error string and endpoint to catch cert/CA changes quickly.
- Make timeouts explicit and test them (unit + integration) to avoid silent behavior changes.
- Instrument retries (attempt count + reason) and alert on spikes to catch dependency slowdowns.
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.