Fix docs_resolve_comment: post a reply with action="resolve" instead of comments.update#1
Open
Baho73 wants to merge 1 commit into
Open
Conversation
The previous implementation called `comments.update({resolved: True})`,
which fails in Drive v3 for two reasons:
1. The API rejects the call with HTTP 400 "Comment content is required"
because every comments.update body must include a non-empty `content`
field, even when the only intended change is the `resolved` flag.
2. Even if `content` is supplied (e.g. by re-sending the existing comment
text), the `resolved` field on the Comment resource is effectively
read-only via comments.update — empirically the call succeeds but the
comment remains open in both the Drive UI and the API.
The canonical way to close a comment in Drive v3 — and what the Docs UI
does internally — is to post a reply with `action="resolve"`. This also
preserves any final-reply text the caller passed in, so it can replace
the previous two-step flow (replies.create + comments.update) with a
single atomic call.
When no `reply` text is provided, fall back to the short placeholder
"Resolved." because Drive requires non-empty `content` on every reply.
The function now also returns `reply_id` and `reply_content` so callers
can audit the closing reply.
Verified end-to-end against a live document: both the `reply=""` and
`reply="..."` paths flip `resolved` to true and the resulting comment is
shown as resolved in the Drive UI.
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
comments.update({resolved: True})withreplies.create(action="resolve")indocs_resolve_comment.replystring.reply_id/reply_contentfor auditability.Bug
The previous implementation always failed:
Two underlying issues in Drive v3 made the old code unusable:
comments.updaterejects any body that doesn't include a non-emptycontentfield — even when the only change you want isresolved: True.contentre-sent, theresolvedfield on the Comment resource is effectively read-only viacomments.update: empirically the call returns 200 but the comment stays open in the Drive UI and the API.The canonical Drive v3 way to close a comment — and what the Docs UI does internally when you click "Resolve" — is to post a reply with
action="resolve". So the fix is to always create such a reply.Behavior
docs_resolve_comment(doc, cid)replies.create(content="Resolved.", action="resolve"), returnsokdocs_resolve_comment(doc, cid, "thanks!")replies.create(content="thanks!", action="resolve"), returnsok+ reply metadataDrive requires non-empty
contenton every reply, so when the caller passes no reply we fall back to the short literal"Resolved.".The two-step flow that used to be
replies.createfollowed bycomments.updateis now a single atomic API call.Test
Verified against a live Google Doc with two open comments:
docs_resolve_comment(doc, cid_a)— no reply → returns{ok: true, reply_id, reply_content: "Resolved."};docs_read_comments(include_resolved=True)confirmsresolved: true.docs_resolve_comment(doc, cid_b, "Подтверждаю, фикс работает.")— with reply → returns the reply text inreply_content; comment isresolved: trueand the reply is visible in the Docs UI.Both cases also flip the comment to the resolved (struck-through) state in the Docs sidebar UI.
Notes
server.pyonly. No new dependencies.main).auth_setup.pyand the rest of the toolset are untouched.