Skip to content

AttributeError: 'tuple' object has no attribute 'decode' when configuring using tuples #334

@vanschelven

Description

@vanschelven
Contributor

Config

CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'channels_redis.pubsub.RedisPubSubChannelLayer',
        'CONFIG': {
            "hosts": [('127.0.0.1', 6379)],
        },
    },
}

Error:



  File "[..]lib/python3.10/site-packages/channels/routing.py", line 71, in __call__
    return await application(scope, receive, send)
  File "[..]lib/python3.10/site-packages/channels/sessions.py", line 47, in __call__
    return await self.inner(dict(scope, cookies=cookies), receive, send)
  File "[..]lib/python3.10/site-packages/channels/sessions.py", line 263, in __call__
    return await self.inner(wrapper.scope, receive, wrapper.send)
  File "[..]lib/python3.10/site-packages/channels/auth.py", line 185, in __call__
    return await super().__call__(scope, receive, send)
  File "[..]lib/python3.10/site-packages/channels/middleware.py", line 26, in __call__
    return await self.inner(scope, receive, send)
  File "[..]lib/python3.10/site-packages/channels/routing.py", line 150, in __call__
    return await application(
  File "[..]lib/python3.10/site-packages/channels/consumer.py", line 94, in app
    return await consumer(scope, receive, send)
  File "[..]lib/python3.10/site-packages/channels/consumer.py", line 46, in __call__
    self.channel_name = await self.channel_layer.new_channel()
  File "[..]lib/python3.10/site-packages/channels_redis/pubsub.py", line 34, in _async_proxy
    return await getattr(layer, name)(*args, **kwargs)
  File "[..]lib/python3.10/site-packages/channels_redis/pubsub.py", line 165, in new_channel
    await self._subscribe_to_channel(channel)
  File "[..]lib/python3.10/site-packages/channels_redis/pubsub.py", line 144, in _subscribe_to_channel
    await shard.subscribe(channel)
  File "[..]lib/python3.10/site-packages/channels_redis/pubsub.py", line 282, in subscribe
    self._ensure_redis()
  File "[..]lib/python3.10/site-packages/channels_redis/pubsub.py", line 349, in _ensure_redis
    pool = aioredis.ConnectionPool.from_url(self.host["address"])
  File "[..]lib/python3.10/site-packages/redis/asyncio/connection.py", line 1400, in from_url
    url_options = parse_url(url)
  File "[..]lib/python3.10/site-packages/redis/asyncio/connection.py", line 1292, in parse_url
    parsed: ParseResult = urlparse(url)
  File "/usr/lib/python3.10/urllib/parse.py", line 392, in urlparse
    url, scheme, _coerce_result = _coerce_args(url, scheme)
  File "/usr/lib/python3.10/urllib/parse.py", line 128, in _coerce_args
    return _decode_args(args) + (_encode_result,)
  File "/usr/lib/python3.10/urllib/parse.py", line 112, in _decode_args
    return tuple(x.decode(encoding, errors) if x else '' for x in args)
  File "/usr/lib/python3.10/urllib/parse.py", line 112, in <genexpr>
    return tuple(x.decode(encoding, errors) if x else '' for x in args)
AttributeError: 'tuple' object has no attribute 'decode'

Offending commit (presumably): 65a0528

Activity

added a commit that references this issue on Oct 21, 2022
cde3939
bbrowning918

bbrowning918 commented on Oct 24, 2022

@bbrowning918
Contributor

Oh, I likely missed the pubsub layer when I reverted the connection bits, the tuple style works for the non-pubsub versions as it just gets unpacked and sent through to redis-py. address is the only reserved kwarg for using a connection URL which was kept/named for what I assume is historical reasons.

Something to the effect of:

if "address" in host:
    pool = aioredis.ConnectionPool.from_url(host["address"])
else:
    pool = aioredis.ConnectionPool(**host)

At https://github.com/django/channels_redis/blob/main/channels_redis/pubsub.py#L349 would bring back the tuple functionality

vanschelven

vanschelven commented on Oct 25, 2022

@vanschelven
ContributorAuthor

address is the only reserved kwarg for using a connection URL which was kept/named for what I assume is historical reasons.

which is a bit weird in itself (to me), e.g. because password is now ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @vanschelven@bbrowning918

      Issue actions

        AttributeError: 'tuple' object has no attribute 'decode' when configuring using tuples · Issue #334 · django/channels_redis