Title: Paragraph.text setter silently detaches comments (and footnote references) added with 1.2 comment support · Issue #1604 · python-openxml/python-docx · GitHub
Open Graph Title: Paragraph.text setter silently detaches comments (and footnote references) added with 1.2 comment support · Issue #1604 · python-openxml/python-docx
X Title: Paragraph.text setter silently detaches comments (and footnote references) added with 1.2 comment support · Issue #1604 · python-openxml/python-docx
Description: Since 1.2 added Document.add_comment(), assigning paragraph.text removes the comment's anchor without any indication. Paragraph.clear() drops every child except w:pPr, which includes w:commentRangeStart / w:commentRangeEnd (these are par...
Open Graph Description: Since 1.2 added Document.add_comment(), assigning paragraph.text removes the comment's anchor without any indication. Paragraph.clear() drops every child except w:pPr, which includes w:commentRange...
X Description: Since 1.2 added Document.add_comment(), assigning paragraph.text removes the comment's anchor without any indication. Paragraph.clear() drops every child except w:pPr, which includes w:commentR...
Opengraph URL: https://github.com/python-openxml/python-docx/issues/1604
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Paragraph.text setter silently detaches comments (and footnote references) added with 1.2 comment support","articleBody":"Since 1.2 added `Document.add_comment()`, assigning `paragraph.text` removes the comment's anchor without any indication. `Paragraph.clear()` drops every child except `w:pPr`, which includes `w:commentRangeStart` / `w:commentRangeEnd` (these are paragraph children, not runs) and the run holding `w:commentReference`. The `\u003cw:comment>` stays in `comments.xml`, anchored to nothing. Word opens the file with no warning and just doesn't show the comment.\n\nSelf-contained repro, python-docx 1.2.0:\n\n from docx import Document\n import zipfile, re\n\n d = Document()\n p = d.add_paragraph(\"The fee is EUR 12,000 per milestone.\")\n d.add_comment(runs=p.runs[0], text=\"Confirm this figure before circulation\", author=\"Reviewer\")\n d.save(\"before.docx\")\n\n d = Document(\"before.docx\")\n d.paragraphs[0].text = \"The fee is EUR 14,000 per milestone.\"\n d.save(\"after.docx\")\n\n for f in (\"before.docx\", \"after.docx\"):\n z = zipfile.ZipFile(f)\n doc = z.read(\"word/document.xml\").decode()\n cm = z.read(\"word/comments.xml\").decode()\n print(f, len(re.findall(r\"commentRange(Start|End)|commentReference\", doc)),\n \"markers,\", len(re.findall(r\"\u003cw:comment \", cm)), \"comments\")\n\n # before.docx 3 markers, 1 comments\n # after.docx 0 markers, 1 comments\n\nThe same happens to `w:footnoteReference` (the footnote body survives in `footnotes.xml`, the reference in the text is gone) and to any `w:ins`/`w:del` wrapping the runs. Probably related to #1519, which reports comments disappearing on save without a repro — I suspect this is the mechanism.\n\nI understand `.text = ...` is documented as replacing the paragraph's content, and that preserving markers across an arbitrary text replacement is not well-defined. But this is the first thing every code sample and every LLM agent reaches for, and the failure is invisible. Options, from small to large:\n\n1. Keep `w:commentRangeStart`/`w:commentRangeEnd` in `clear()` (they are not content), and re-emit `w:commentReference` for each surviving range at the end of the new run. The comment then anchors to the whole new text, which is what Word does when you retype a commented passage.\n2. At minimum, a warning in the `text` setter docstring and in the comments section of the docs that setting text removes comment anchors, footnote references and tracked-change markup in that paragraph.\n3. Emit a `warnings.warn` when `clear()` is about to drop a comment range or footnote reference.\n\nHappy to open a PR for (1) or (2) if either is acceptable. Found while measuring what verification steps catch on agent-edited documents (github.com/Dmitry-Kov/ooxml-integrity).\n\npython-docx 1.2.0, Python 3.9.6, macOS","author":{"url":"https://github.com/Dmitry-Kov","@type":"Person","name":"Dmitry-Kov"},"datePublished":"2026-09-07T14:43:12Z","url":"https://github.com/python-openxml/python-docx/issues/1604"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a9975437-3f84-3b82-1678-6474aff29104 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8A26:4D728:797FD0:8B1219:6AFF6390 |
| html-safe-nonce | 2d789bc966af8d4ef873e3c93f226a59f529530d96c6ac60fbd501f8bff7ea8a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QTI2OjRENzI4Ojc5N0ZEMDo4QjEyMTk6NkFGRjYzOTAiLCJ2aXNpdG9yX2lkIjoiNTI2MDU2MzU0MTc5MzkyMzk4NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 00b76fc7de3a790c0a611aece26b361c5ab33f21bf38c763e460c2f31a84260d |
| hovercard-subject-tag | issue:5376129790 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-openxml/python-docx/1604/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bff209254feabc238cf43a1c10b59562207cb57347ff5e381c735e71c7b20db1/python-openxml/python-docx/issues/1604 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bff209254feabc238cf43a1c10b59562207cb57347ff5e381c735e71c7b20db1/python-openxml/python-docx/issues/1604 |
| og:image:alt | Since 1.2 added Document.add_comment(), assigning paragraph.text removes the comment's anchor without any indication. Paragraph.clear() drops every child except w:pPr, which includes w:commentRange... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Dmitry-Kov |
| hostname | github.com |
| expected-hostname | github.com |
| None | 41b58589a1c4eda1e3c8904144a412b88ca4455f63ca2ad3629f2e9f3c3a1d12 |
| turbo-cache-control | no-preview |
| go-import | github.com/python-openxml/python-docx git https://github.com/python-openxml/python-docx.git |
| octolytics-dimension-user_id | 3403760 |
| octolytics-dimension-user_login | python-openxml |
| octolytics-dimension-repository_id | 13592924 |
| octolytics-dimension-repository_nwo | python-openxml/python-docx |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 13592924 |
| octolytics-dimension-repository_network_root_nwo | python-openxml/python-docx |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8968d6d6acc65d74e4df332d23932dd3fd0502a4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width