Bug 405152

Summary: Copy/Paste local contact in KAddressBook breaks data in ~/.local/share/contacts/
Product: [Applications] kaddressbook Reporter: Helmar Gerloni <helmar>
Component: generalAssignee: kdepim bugs <kdepim-bugs>
Status: REPORTED ---    
Severity: normal CC: helmar, tokoe
Priority: NOR    
Version: GIT   
Target Milestone: ---   
Platform: Neon   
OS: Linux   
Latest Commit: Version Fixed In:

Description Helmar Gerloni 2019-03-06 20:31:08 UTC
When copy/pasting a contact in KAddressBook the data in ~/.local/share/contacts/ gets corrupted. Always reproducible in current KDE Neon (kaddressbook 4:18.12.2+p18.04+git20190228.0023-0) and also on Debian Buster.

Steps to reproduce:
- Start KAddressBook with empty local address book "Personal Contacts".
- Create one contact in the local "Personal Contacts"
- Contact shows up in ~/.local/share/contacts/113b24d7-6248-48ac-9087-01ca561a2955.vcf.
- Right click on the contact, Copy Contact To -> Personal Contacts.
- Contact now shows up twice in the address book "Personal Contacts" (as expected), but it still shows up only once in ~/.local/share/contacts/.
- When you modify one of the contacts in KAddressBook, the File 113b24d7-6248-48ac-9087-01ca561a2955.vcf in ~/.local/share/contacts/ is always overwritten with the last modified contact.
- So while in KAddressBook everything looks as expected (because it uses the data from the Akonadi cache?) the "real data" in ~/.local/share/contacts/ is corrupted; one contact is missing.

This may seem like a minor problem, but it gets serious when you copy the contact missing in ~/.local/share/contacts/ to a DAV server (Nextcloud in my case).
The contact is not copied, and Akonadi shows the following error (in ~/.xsession-errors):
  org.kde.pim.davresource: DavGroupwareResource::onItemFetched: Failed to parse item data.  "https://nextcloud.mydomain.tld/remote.php/dav/addressbooks/users/testuser/contacts/1551900153.R643.vcf"
The error is obvious since the Nextcloud server responds with a 401 "http unauthorized" error and a "Not Found" html message (the contact does not exist on the server).
From now on Akonadi refuses to synchronize any data with the DAV server, also the calendar is not synchronized any more (by the way this seems to be another error).
After removing the broken contact from the Nextcloud addressbook in KAddressBook followed by "akonadictl restart" everything (in Nextcloud) works again as expected.
The problem with the local contact can simply be fixed by deleting the broken contact from KAddressBook, but it's quite tricky to find out what really went wrong when running into this problem. Also when backing up the "real data" in ~/.local/share/contacts/ you do not get all contacts you see in KAddressBook.