Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vanschelven opened this issue Oct 21, 2022 · 2 comments

Comments

@vanschelven
Copy link
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

vanschelven added a commit to vanschelven/channels_redis that referenced this issue Oct 21, 2022
Fixes django#334 

A more thorough (and backward compatible) fix would be to actually make tuples work again.
@bbrowning918
Copy link
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
Copy link
Contributor Author

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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants