Jump to solution
Verify

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%.

Jump to Verify Open PR/Commit
@@ -1153,6 +1153,7 @@ def __init__( redis_connect_func=None, credential_provider: Optional[CredentialProvider] = None, + command_packer=None, ): """
repro.py
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__()
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 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).
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 3.9 in real deployments (not just unit tests).
  • Surfaces as: Traceback (most recent call last):

Proof / Evidence

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.”
@prokazov · 2023-02-07 · source
“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”
@alee · 2023-02-07 · source
“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…”
@woutdenolf · 2023-02-07 · source
“Actually SSLConnection does call super().__init__ so that one should be fine.”
@woutdenolf · 2023-02-07 · source

Failure Signature (Search String)

  • redis_conn.ping()

Error Message

Stack trace
error.txt
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

repro.py
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

When NOT to use: This fix should not be applied if the connection logic is fundamentally altered or if using a different connection type.

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)
onceonly.py
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)

See OnceOnly SDK

When NOT to use: 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.

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.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

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

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

  • 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

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.