Skip to content

Compile channel_capacity patterns in BaseChannelLayer - #2232

Closed
Cherith1222 wants to merge 1 commit into
django:mainfrom
Cherith1222:fix/1423-channel-capacity-dict
Closed

Cherith1222 wants to merge 1 commit into
django:mainfrom
Cherith1222:fix/1423-channel-capacity-dict

Conversation

@Cherith1222

Copy link
Copy Markdown

Summary

BaseChannelLayer stored channel_capacity as the raw dict, while get_capacity() iterates self.channel_capacity as (compiled pattern, capacity) pairs. Passing channel_capacity into InMemoryChannelLayer therefore raised ValueError the first time capacity was looked up, including on send().

__init__ now runs the existing compile_capacities(), the same step channels_redis already takes. Glob strings are compiled, and precompiled regexes are left as-is. Unmatched channel names still use the default capacity.

Fixes #1423

Test

tests/test_inmemorychannel.py::test_send_channel_capacity constructs InMemoryChannelLayer(capacity=3, channel_capacity={"small-*": 1, re.compile(r"^big-"): 5}). On the previous code this failed with ValueError: too many values to unpack while iterating the raw dict. After this change it passes: small-channel has capacity 1, big-channel has capacity 5, other-channel keeps the default 3, and a second send() to small-channel raises ChannelFull.

AI assistance

This change was written with AI assistance (Cursor). It has not been reviewed by a human.

BaseChannelLayer stored channel_capacity as the raw dict, but get_capacity() iterates it as (compiled pattern, capacity) pairs. Passing channel_capacity to InMemoryChannelLayer therefore raised ValueError on the first send(). Compile the patterns in __init__, as channels_redis already does, so glob strings and precompiled regexes both work.

AI-assisted (Cursor); not yet reviewed by a human.
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 this pull request may close these issues.

Is this a bug in get_capacity method ?

2 participants