Skip to content

Redis SSL Connection Error with redis-py #2081

@yju0808

Description

@yju0808

Redis SSL Connection Error with redis-py

Description

When using RedisSession.from_url() with SSL-enabled Redis URLs (rediss://), the application crashes with a TypeError when redis-py 7.x is installed. This issue occurs because RedisSession.from_url() passes ssl=True as a keyword argument, which is incompatible with redis-py 7.x's connection API.

Error Message

TypeError: AbstractConnection.__init__() got an unexpected keyword argument 'ssl'

Environment

  • openai-agents: 0.5.0
  • redis-py: 7.0.1 (installed via openai-agents[redis])
  • Python: 3.12
  • Redis Server: Upstash Redis (SSL required, rediss:// URL scheme)

Root Cause

In redis-py 7.x, AbstractConnection.__init__() does not accept an ssl boolean parameter. The rediss:// URL scheme automatically triggers SSL connection handling.

However, RedisSession.from_url() in agents/extensions/memory/redis_session.py adds ssl=True to kwargs when it detects a rediss:// URL:

@classmethod
def from_url(cls, session_id: str, *, url: str, redis_kwargs: dict[str, Any] | None = None, **kwargs: Any) -> RedisSession:
    redis_kwargs = redis_kwargs or {}
    
    # Parse URL to determine if we need SSL
    parsed = urlparse(url)
    if parsed.scheme == "rediss":
        redis_kwargs.setdefault("ssl", True)  # ❌ Causes TypeError in redis 7.x
    
    redis_client = redis.from_url(url, **redis_kwargs)
    session = cls(session_id, redis_client=redis_client, **kwargs)
    session._owns_client = True
    return session

This ssl=True kwarg gets passed through the call chain:

redis.from_url() → ConnectionPool.from_url() → ConnectionPool.__init__() → AbstractConnection.__init__()

AbstractConnection.__init__() does not accepts the ssl parameter, resulting in the TypeError.

Reproduction

import asyncio
from agents.extensions.memory import RedisSession

async def test():
    # This fails with redis 7.x
    session = RedisSession.from_url(
        "test_session",
        url="rediss://default:password@host:6379"
    )
    await session.add_items({"key1": {"data": "value1"}})

asyncio.run(test())

Impact

This affects any user of openai-agents[redis] connecting to SSL-enabled Redis servers, as the current dependency specification allows redis-py 7.x:

redis = ["redis>=6.4.0"]

In earlier versions of redis-py, it’s unclear whether this issue occurred, but in version 7.x it definitely does.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions