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

Fix docs for "hosts" #335

Closed
wants to merge 2 commits into from
Closed

Fix docs for "hosts" #335

wants to merge 2 commits into from

Conversation

vanschelven
Copy link
Contributor

Fixes #334

A more thorough (and backward compatible) fix would be to actually make tuples work again.

Fixes django#334 

A more thorough (and backward compatible) fix would be to actually make tuples work again.
The pointer to redis.connection.Connection was misleading, because in actualitly from_url is used:

https://github.com/django/channels_redis/blob/95d87449c2b899c1cfdf8a10cfa1425e30127ef2/channels_redis/pubsub.py#L349
@vanschelven vanschelven changed the title Fix docs to reflect that tuples don't work Fix docs for "hosts" Oct 21, 2022
Copy link
Contributor

@sevdog sevdog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tuple "decoding" is not working only in RedisPubSubChannelLayer, the base RedisChannelLayer has a dedicated method to handle it:

def decode_hosts(self, hosts):
"""
Takes the value of the "hosts" argument passed to the class and returns
a list of kwargs to use for the Redis connection constructor.
"""
# If no hosts were provided, return a default value
if not hosts:
return [{"address": "redis://localhost:6379"}]
# If they provided just a string, scold them.
if isinstance(hosts, (str, bytes)):
raise ValueError(
"You must pass a list of Redis hosts, even if there is only one."
)
# Decode each hosts entry into a kwargs dict
result = []
for entry in hosts:
if isinstance(entry, dict):
result.append(entry)
elif isinstance(entry, tuple):
result.append({"host": entry[0], "port": entry[1]})
else:
result.append({"address": entry})
return result

The right way to address #334 would be to move that method out from RedisChannelLayer to utils module and to use it for both layers.

Anyway the docs for RedisChannelLayer should not be changed.

@carltongibson
Copy link
Member

Resolved in #352

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

AttributeError: 'tuple' object has no attribute 'decode' when configuring using tuples
3 participants