Whole file

Bouke/docx-mailmerge

The author described this change as Merge rows should not fail if there is a table which is not available in template. It counts as a record because the check below fails on the code as it stood at 1ae8a2975 and passes on b43774874, with nothing else changed between the two runs.

Fix saved2016-04-27
Sharing licenceMIT · LICENSE.txt
Change size+7 5

What the code was meant to do, written into the code itself as a save note

Merge rows should not fail if there is a table which is not available in template

The change

149149
150150 def merge_rows(self, anchor, rows):
151151 table, idx, template = self.__find_row_anchor(anchor)
152- del table[idx]
153- for i, row_data in enumerate(rows):
154- row = deepcopy(template)
155- self.merge([row], **row_data)
156- table.insert(idx + i, row)
152+ if table is not None:
153+ del table[idx]
154+ for i, row_data in enumerate(rows):
155+ row = deepcopy(template)
156+ self.merge([row], **row_data)
157+ table.insert(idx + i, row)
157158
158159 def __find_row_anchor(self, field, parts=None):
159160 if not parts:
163164 for idx, row in enumerate(table):
164165 if row.find('.//MergeField[@name="%s"]' % field) is not None:
165166 return table, idx, row
167+ return None, None, None
166168

The check that tells the two apart

failpass·tests/test_merge_table_rows.py::MergeTableRowsTest::test_merge_rows_no_table

Check file tests/test_merge_table_rows.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it1ae8a2975829c08050da4316dc37eb5927b49d44
Broken version dated2016-04-05
Modulemailmerge
Units changedMailMerge
Fingerprint485fdae2c7645476
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.