Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deep nesting subdocuments breaks bullet lists and number lists #580

Open
rgrignon1 opened this issue Jan 14, 2025 · 0 comments
Open

Deep nesting subdocuments breaks bullet lists and number lists #580

rgrignon1 opened this issue Jan 14, 2025 · 0 comments
Labels

Comments

@rgrignon1
Copy link

Describe the bug

In a project with multiple layers of subdocuments, when inserting a subdocument containing any type of list, its style get inconsistently modified.

A similar bug ( #500 ) was reported more than a year ago (and still isn't fixed), but this one shows deeper inconsistencies, such as numbered lists becoming bullet lists, bullet lists becoming numbered list and numbered lists merged together or restarting their count.

To Reproduce

(all tested with python 3.11.8, docxtpl 0.19.1 and python-docx 1.1.2)

2 tests are made to show different ways the bugs manifest themselves.

  • In the first one, a docx template is made with 2 numbered lists and 2 bullet lists generated from the variables
  • In the second one, only one numbered list and one bullet list are used

Both templates are shown on the first file on the left side of each screenshots.

Then, for each test, the file is embedded 3 times through the same template consisting only of a single variable:

{{ PREVIOUS_FILE }}

Finally, the python script to generate the files is run as is:

from docxtpl import DocxTemplate


first_tpl_path= "./path/first_template.docx"
embedding_tpl_path= "./path/embedding_template.docx"

file_1_path = "./path/first_file.docx"
file_2_path = "./path/second_file.docx"
file_3_path = "./path/third_file.docx"
file_4_path = "./path/fourth_file.docx"

tpl_1 = DocxTemplate(first_tpl_path)
tpl_1.render({
    "numbered_list_1": ["item 1", "item 2"],
    "bullet_list_1": ["item 3", "item 4"],
    "numbered_list_2": ["item 5", "item 6", "item 7"],
    "bullet_list_2": ["item 8", "item 9", "item 10"]
})
tpl_1.save(file_1_path)

tpl_2 = DocxTemplate(embedding_tpl_path)
sub_file_1 = tpl_2.new_subdoc(file_1_path)
tpl_2.render({"PREVIOUS_FILE": sub_file_1})
tpl_2.save(file_2_path)

tpl_3 = DocxTemplate(embedding_tpl_path)
sub_file_2 = tpl_3.new_subdoc(file_2_path)
tpl_3.render({"PREVIOUS_FILE": sub_file_2})
tpl_3.save(file_3_path)

tpl_4 = DocxTemplate(embedding_tpl_path)
sub_file_3 = tpl_4.new_subdoc(file_3_path)
tpl_4.render({"PREVIOUS_FILE": sub_file_3})
tpl_4.save(file_4_path)

Expected behavior

All generated files should be identical to the first one (second file on the left on each screenshot).

Instead, for the first test, on the 3rd file, all bullet points get turned into numbered lists and all four lists are treated as a single one, and on the fourth file, the second item of the first list start a new counter for the remaining items.

And on the second test, the numbered list gets converted into bullet points instead on the third file. On the fourth one, they all turn back into numbered list just like for the first test, including counting twice the first item.

Screenshots

nested_document_issue

nested_document_issue_2

Additional context

Different templates can generate different results. Running the same test with the same template multiple times seems to consistently generate the same errors, and changing the number of items per list in the variables doesn't seem to influence how the bugs manifest themselves.

Those are only a sample of what I encountered on my personal project that I could minimally reproduce, but I have also encountered other bugs, such as the text content of a cell in a table being converted into a bullet list, or left indent on bullet list changing from 0 to the default Word value randomly.

This is becoming extremely irritating because each time I try to add something, there's a new bug that require manual editing at the end of my pipeline!

@rgrignon1 rgrignon1 added the bug label Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant