Repository navigation
Compile channel_capacity patterns in BaseChannelLayer - #2232
Closed
Cherith1222 wants to merge 1 commit into
Closed
Cherith1222 wants to merge 1 commit into
Cherith1222 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BaseChannelLayerstoredchannel_capacityas the raw dict, whileget_capacity()iteratesself.channel_capacityas(compiled pattern, capacity)pairs. Passingchannel_capacityintoInMemoryChannelLayertherefore raisedValueErrorthe first time capacity was looked up, including onsend().__init__now runs the existingcompile_capacities(), the same stepchannels_redisalready takes. Glob strings are compiled, and precompiled regexes are left as-is. Unmatched channel names still use the defaultcapacity.Fixes #1423
Test
tests/test_inmemorychannel.py::test_send_channel_capacityconstructsInMemoryChannelLayer(capacity=3, channel_capacity={"small-*": 1, re.compile(r"^big-"): 5}). On the previous code this failed withValueError: too many values to unpackwhile iterating the raw dict. After this change it passes:small-channelhas capacity 1,big-channelhas capacity 5,other-channelkeeps the default 3, and a secondsend()tosmall-channelraisesChannelFull.AI assistance
This change was written with AI assistance (Cursor). It has not been reviewed by a human.