Skip to content

fix(docx): read styles with the invalid type "list" - #4831

Merged
dolfim-ibm merged 1 commit into
docling-project:mainfrom
loickouao:fix/docx-list-style-type
Oct 19, 2026
Merged

dolfim-ibm merged 1 commit into
docling-project:mainfrom
loickouao:fix/docx-list-style-type

Conversation

@loickouao

Copy link
Copy Markdown

A DOCX fails to convert with ValueError: WD_STYLE_TYPE has no XML mapping for 'list' when its styles.xml declares a style with w:type="list" (#4830).

list is not an ST_StyleType value, and python-docx raises when it reads it. To find a default style, python-docx reads the type of every style. The backend asks for the default paragraph style when it opens the file (since 2.115), and paragraph.style asks for it on a paragraph without w:pStyle. A try/except around the call in __init__ would leave the second path, so this PR changes the type to numbering once the document is loaded. numbering is the numbering style type (WD_STYLE_TYPE.LIST in python-docx). No other style type changes.

Issue resolved by this Pull Request:
Resolves #4830

Checklist:

  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary.
  • Tests have been added, if necessary.

Review evidence:

  • Before and after: test_list_style_type_does_not_fail_conversion builds the file at test time, once with the body paragraph styled and once without w:pStyle. Both cases fail on main with the ValueError and pass on this branch. With only a try/except around styles.default() in __init__, the case without w:pStyle still fails.
  • No change on existing files: no .docx under tests/data has a list style, and the reference tests pass unchanged.
  • Tests: all 305 tests in tests/test_backend_msword*.py and tests/test_office_image_modes.py pass.
  • Tooling: make validate passes (ruff, ty, tach, max lines).
  • Not run: the real press release that showed the bug is not available here. The fix was tested on generated files only.
  • Independent of fix(docx): keep XML comments in NOTES, drop processing instructions #4584: both branches touch MsWordDocumentBackend.__init__, and they merge without conflict.

Some files declare a style with w:type="list" in styles.xml. ST_StyleType
has no such value, and python-docx raises ValueError when it reads it. It
reads the type of every style to find a default style: the backend does
that when it opens the file (since 2.115), and the style of a paragraph
without w:pStyle does it too. So one such style failed the whole
conversion.

Once the document is loaded, change the type to "numbering", the
numbering style type (WD_STYLE_TYPE.LIST in python-docx).

Signed-off-by: loickouao <diegoloic@hotmail.fr>
@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @loickouao, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working docx issue related to docx backend labels Oct 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit cfb5bd7158. The analysis read the diff only. It did not run code from this pull request.

The PR fixes a ValueError raised by python-docx when a DOCX styles.xml declares a style with w:type="list". It adds _normalize_list_style_types to rewrite any such list type to numbering immediately after the document loads, and adds a parametrized test that builds the offending file at test time.

Topic labels added: bug, docx.

CI safety: no concern found. A maintainer must still approve CI.

1 related pull request(s) in the same code
PR State Signal Assessment
#4584 open referenced as #4584; changes the same code related: Both PRs touch MsWordDocumentBackend.__init__ and insert a normalisation call at the same location, but they fix different bugs: #4584 removes XML comment and processing-instruction nodes; this PR rewrites an invalid style type. The overlap is positional only.

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI first review (advisory): no blocker found

This review covers the full diff at cfb5bd7158. It read the code and did not run it.

The fix correctly patches w:type="list" to "numbering" in the XML before python-docx reads the style type. The XML attribute name and replacement value are both verified against the python-docx source. The test covers the two failure paths described in the PR. No regressions or missing cases were found.

A maintainer makes the merge decision. This review never approves the pull request.

@github-actions github-actions Bot added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Oct 14, 2026
@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@dolfim-ibm dolfim-ibm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@dolfim-ibm
dolfim-ibm merged commit 0fe65b2 into docling-project:main Oct 19, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) bug Something isn't working docx issue related to docx backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DOCX conversion fails when styles.xml declares a style with w:type="list"

2 participants