fix: drop recipient from targeted message update payload - #571
Open
Corina (corinagum) wants to merge 1 commit into
Open
fix: drop recipient from targeted message update payload#571Corina (corinagum) wants to merge 1 commit into
Corina (corinagum) wants to merge 1 commit into
Conversation
Teams rejects targeted-message updates that carry a recipient with "BadArgument: Cannot edit Recipient of Targeted Message", because the recipient of an existing targeted message cannot be edited. send_or_update_activity now uses the recipient only to select the targeted update endpoint and strips it from the outbound payload. The returned SentActivity still reports the recipient the caller passed in. Ports microsoft/teams.ts#739 (fixes microsoft/teams.ts#738). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3793b160-edf5-405b-a920-5c774273b68b
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes targeted message updates by ensuring recipient is used only to select the targeted update endpoint and is not serialized into the update request body (which Teams rejects). This aligns the Python SDK behavior with the referenced TypeScript fix and preserves the caller-visible recipient in the returned SentActivity.
Changes:
- In targeted update flows, create an update payload with
recipient=Noneso it is omitted from the wire body (exclude_none=True), while preserving the original recipient in the returned result. - Update/replace the targeted update test to assert endpoint selection, payload serialization behavior, and that the caller still receives the original recipient.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/apps/src/microsoft_teams/apps/activity_send.py | Drops recipient from targeted update payloads while keeping it on the returned SentActivity. |
| packages/apps/tests/test_activity_context.py | Replaces the prior assertion with a test that verifies recipient is omitted from the targeted update payload but preserved for the caller. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Ports microsoft/teams.ts#739 (fixes microsoft/teams.ts#738) to the Python SDK. Same bug, same root cause, no equivalent issue filed on this repo.
Why
Updating a targeted message through
ctx.sendfails. Settingidon aMessageActivityInputthat also carries a targeted recipient correctly routes the call toupdate_targeted_activity, butrecipientis still serialized into the request body, and Teams rejects it:The recipient of an existing targeted message cannot be edited, so it must not appear in an update payload. It is only useful for deciding which endpoint to call.
What changed
send_or_update_activityinpackages/apps/src/microsoft_teams/apps/activity_send.py(the Python counterpart of TypeScript'sActivitySender) now splits the targeted update out of the shared update path:activity.model_copy(update={"recipient": None}). The client dumps withexclude_none=True, so the key disappears from the wire body.SentActivitystill reports the recipient the caller passed in. Without this,result.activity_params.recipientwould come backNoneafter an update, which matches the guarantee the TypeScript fix makes about its own return value.This covers every send path, since
ctx.send,App.send, andFunctionContext.sendall funnel through this helper.Deliberately unchanged:
ConversationActivityClient.update_targetedstill sends whatever it is handed.examples/targeted-messagescalls that client directly and passes no recipient, so it is unaffected, and this keeps the fix at the same layer as the TypeScript port rather than diverging the two SDKs at the API-client boundary.Tests
test_targeted_update_preserves_recipientasserted the buggy behavior, so it is replaced bytest_targeted_update_drops_recipient_from_payload, which checks that the targeted endpoint is still chosen, the payload has norecipient(both on the model and in the serialized body), and the caller still gets the recipient back.Red-green verified rather than assumed: reverting either half of the fix independently fails the new test.
Validation
pytest packages— 1052 passedpyright— 0 errors, 0 warningsruff check/ruff format --check— clean