Repository navigation
fix(dingtalk): skip group messages outside the whitelist instead of crashing - #3284
Merged
zhayujie merged 1 commit intoSep 29, 2026
Conversation
…rashing ChatChannel._compose_context returns None when the group name is not in group_name_white_list, and every channel guards with `if context:` before touching it. handle_group wrote context['no_need_at'] one line above that guard, so a skipped group message raised TypeError instead of being skipped. process() swallows it into STATUS_SYSTEM_EXCEPTION while _check has already recorded the message id, so the redelivered message is deduplicated and the group member never gets an answer.
Owner
|
Merged, thanks for the fix! |
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.
Fixes #3283
What does this PR do?
handle_group()assignedcontext['no_need_at'] = Trueone line above its ownif context:guard.ChatChannel._compose_context()returnsNonewhen the group is not ingroup_name_white_list(channel/chat_channel.py, the branch that logsNo need reply, groupName not in whitelist), so instead of skipping the message it raisedTypeError: 'NoneType' object does not support item assignment. The fix moves the assignment inside the guard — one line, no other branch touched.Type of change
Why it is a real defect
Nonereturn is the base class's documented contract, and the private twin right above already honours it:handle_single()composes the context and then checksif context:(channel/dingtalk/dingtalk_channel.py:727-732).handle_group()was the only place in the channel that wrote into the value before checking it, and the next method,_maybe_attach_dingtalk_stream(), even guardsif not context: return context— so the code right below was already written for aNoneit never got to see.process()catches it and answersAckMessage.STATUS_SYSTEM_EXCEPTION, while_checkhas already stored the message id inreceivedMsgs(channel/dingtalk/dingtalk_channel.py:88-91), so DingTalk's redelivery of that message is deduplicated and dropped. The group member receives nothing at all.config.py:71sets"group_name_white_list": ["group1", "group2"], so on a fresh install every DingTalk group message hits it and the whitelist feature cannot be used on this channel.What changed
channel/dingtalk/dingtalk_channel.py:context['no_need_at'] = Truemoved from beforeif context:to the first statement inside it. Behaviour for a whitelisted group is unchanged — the flag is still set beforeproduce(), which is whatchannel/chat_channel.py:301reads to decide whether a group reply needs an@.tests/test_dingtalk_group_context_guard.py(new, no network, no SDK):test_group_message_without_a_context_is_skipped—_compose_contextreturningNone(what the base class really returns for a non-whitelisted group) must not raise and must not produce a turn.test_whitelisted_group_message_still_marks_no_need_at— control: a real context is still markedno_need_atand still reachesproduce().Both reuse the
_bare_channel/_contexthelpers and thedingtalk_streamstub fromtests/test_dingtalk_streaming_cards.py, so no optional dependency is added.How I checked it
4c00ca6d:1 failed, 1 passed— the failure is exactlyTypeError: 'NoneType' object does not support item assignmentatdingtalk_channel.py:807.2 passed; the whole DingTalk area is34 passed(pytest tests/ -q -k dingtalk).36 failed, 2066 passed, 34 skippedvs36 failed, 2064 passed, 34 skippedon the same base commit with the branch reverted, and the 36 names are identical — those are pre-existing failures on Windows, none of them inchannel/dingtalk.ruff check channel/dingtalk/dingtalk_channel.py tests/test_dingtalk_group_context_guard.py --select F --ignore F403,F405: all checks passed.Checklist