Bug 106959 - MAILMERGE wrong if document starts with table when output saved as individual documents using MM toolbar
Summary: MAILMERGE wrong if document starts with table when output saved as individual...
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
4.4.0.3 release
Hardware: All All
: high normal
Assignee: Not Assigned
URL:
Whiteboard: target:7.5.0 target:7.4.2
Keywords: bibisected, regression
: 139072 150885 (view as bug list)
Depends on:
Blocks: Mail-Merge
  Show dependency treegraph
 
Reported: 2017-04-04 21:27 UTC by Braciolo
Modified: 2022-09-21 09:57 UTC (History)
9 users (show)

See Also:
Crash report or crash signature:


Attachments
Example of db to test the bug (8.08 KB, application/vnd.oasis.opendocument.spreadsheet)
2017-04-20 17:40 UTC, Braciolo
Details
Example of mail merge odt (with table) to test the bug (8.31 KB, application/vnd.oasis.opendocument.text)
2017-04-20 17:45 UTC, Braciolo
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Braciolo 2017-04-04 21:27:41 UTC
Description:
In mail merge with a simple document, even with only a merge field, if the document contains a table in the top of the page (before the fields) when you "Save merged documents" as individual documents, you obtain the exact number of output files, but the first and the second files are identical (in the content) and related to the first record of data. The last obtained file contains the merged content of the 2 last records of data. The behavior returns normal when the table is removed from the mail merge master document.
The same "tabled" document merged with Openoffice does not present this  behavior. 




Steps to Reproduce:
1. create a new empty writer document (odt);
2. with Tools -> "Mail Merge Wizard" select an  "Address List" (a simple ods file with a field of data);
3. insert a table on the top of the page;
4. open "Data Sources" (CTRL+SHIFT+F4);
5. insert the field in the document with drag and drop after the table position;
6. on the "Mail Merge toolbar" select "Save merged documents" -> "Save as individual document" -> Save Documents;
7. select a name for merged individual files; 


Actual Results:  
The number of the files obtained is correct (the same of the rows of data).
The first and the second file (name_0, name_1) have the same content, if the rows of data contains [1,2,3,..,n] the first and the second file refer to the same value of data "1". The last file name_n-1 contains 2 pages with value of n-1 and n rows data.

Expected Results:
The first file contains the first data row.
The second file contains the second data row.
....
The last file contains the last data row.


Reproducible: Always

User Profile Reset: No

Additional Info:
If the table (on the top of the page) is deleted the behavior of mail merge becomes normal.


User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0
Comment 1 Braciolo 2017-04-20 17:40:26 UTC
Created attachment 132720 [details]
Example of db to test the bug

Simple db to test writer bug
Comment 2 Braciolo 2017-04-20 17:45:22 UTC
Created attachment 132721 [details]
Example of mail merge odt (with table) to test the bug

Use this odt file with the db (other attachment) to test the behavior of writer
Comment 3 Timur 2017-07-13 17:01:00 UTC Comment hidden (obsolete)
Comment 4 Timur 2017-07-13 17:19:29 UTC Comment hidden (obsolete)
Comment 5 Timur 2017-07-14 09:21:56 UTC
Whatever the cause of this bug is, it still exists with 6.0+. 
Looks like the cause is table before field, and even that only if document starts with the table. If there's line before, not reproduced. 
I reproduced on yours and on the other example, like my data source. Repro with 4.4.0 so bibisect hopefully possible.
I change the generic title to point to table issue.
Comment 6 Braciolo 2017-07-17 13:21:17 UTC
Thanks for the attention, now the bug's title is clearer. The bug is especially dangerous if you use the automatic sending of emails with custom attachments, a person's attachment might be sent to others with privacy issues.
Comment 7 Buovjaga 2018-05-24 12:21:25 UTC
Bibisected on Windows to range https://cgit.freedesktop.org/libreoffice/core/log/?qt=range&q=1964870db4ad1e4334e8fc5050795469dc1fb05e...64f186cfda29d3d92c0ebd9c4ee7992898a00134

of which https://cgit.freedesktop.org/libreoffice/core/commit/?id=c808802e94eba48dc23d7fca133ed35c17feb163 seems to be the cause

commit c808802e94eba48dc23d7fca133ed35c17feb163 (patch)
tree 8faaf4dfaec9a046137d57eb084d0d74f9afca66
parent 8e174eab91acec0f1578af4dac23be76dce700af (diff)
MM: introduce SwDoc::Append helper function
This drops all the specialized, workaround code from MM, introduced
to use the SwFEShell::Paste function and additionally merges
and renames SwDoc::Paste into SwDoc::Append.

There is still a little common codepath, therefore this adds
comments to always update both functions.

Change-Id: I704b3ef3257dd977dac95e16e25049ff8ade97ed
Reviewed-on: https://gerrit.libreoffice.org/10967

Adding Jan-Marek to CC
Comment 8 QA Administrators 2019-05-25 02:56:54 UTC Comment hidden (obsolete)
Comment 9 NISZ LibreOffice Team 2020-05-04 15:04:09 UTC
Still happens in

Version: 7.0.0.0.alpha0+ (x64)
Build ID: a40455528c4ec2c079444f320a02d1946e1d8ac9
CPU threads: 4; OS: Windows 6.3 Build 9600; UI render: GL; VCL: win; 
Locale: hu-HU (hu_HU); UI-Language: en-US
Calc: CL
Comment 10 NISZ LibreOffice Team 2021-09-13 14:50:26 UTC
*** Bug 139072 has been marked as a duplicate of this bug. ***
Comment 11 Oleg Shchelykalnov 2021-10-07 10:09:55 UTC
Got similar issue when use MailMerge and XMailMergeListener to fill text fields. When I use individual document text field stores Content and Value property from previous row. If I use merged document issue doesn't occur.
Comment 12 Timur 2022-09-13 09:06:47 UTC Comment hidden (obsolete)
Comment 13 Timur 2022-09-14 09:01:02 UTC
*** Bug 150885 has been marked as a duplicate of this bug. ***
Comment 14 Timur 2022-09-14 09:14:12 UTC
So, thanks to Mike, it's more clear now. 
Bug is: MAILMERGE wrong if document starts with table when output saved as individual documents using Mail Merge toolbar (Data Sources toolbar and it's Mail Merge icon in older LO).
Bug no repro if mailmerge used via Print.

With original attachment 132721 [details], after table is the fields, so error is that the second document is identical to the first one.
With 3-page ODT attachment from duplicate bug 150885, after table there's paragraph and then field, error is that 1st result ODT is 2 pages, 2nd ODT is then 3 wrong pages, last ODT is 4 pages.

While we can use Print, some users will go to MM toolbar and this is already bibisected regression, so I find it justified to set High.
Comment 15 Commit Notification 2022-09-15 12:01:06 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/eb30df9b8e86f756ebc66be86ae2eb345fafc850

tdf#106959: use table's first content node for cursor cleanup

It will be available in 7.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 16 Andrew 2022-09-16 09:59:08 UTC
Version: 7.5.0.0.alpha0+ / LibreOffice Community
Build ID: eab9015d1e17950ee5a49f93a6ad40e7726f5050
CPU threads: 1; OS: Linux 5.10; UI render: default; VCL: gtk3
Locale: ru-RU (ru_RU.UTF-8); UI: en-US
Calc: threaded

Mail Merge works fine.
Comment 17 Commit Notification 2022-09-16 12:31:28 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "libreoffice-7-4":

https://git.libreoffice.org/core/commit/87f17803a907c29a121fcb84588da98a51cca543

tdf#106959: use table's first content node for cursor cleanup

It will be available in 7.4.2.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 18 Timur 2022-09-16 13:27:04 UTC
> Mail Merge works fine.
So Verified. Great.

This was sneaky bug, as it's common to start mail merge document with company logo in table.