Error while updating birthday calendar: Calendar object with uid already exists in this calendar collection

Hello,

I had previously problems with the birthday calendar as one contact couldn’t be parsed. I could solve the problem and want to trigger update of birthday calendar as some contacts are missing:
sudo -u http php occ -vvv dav:sync-birthday-calendar username

However, it stops with following exception:
In CalDavBackend.php line 1068:

  [Sabre\DAV\Exception\BadRequest]                                      
  Calendar object with uid already exists in this calendar collection.  
                                                                        

Exception trace:
  at /usr/share/webapps/nextcloud/apps/dav/lib/CalDAV/CalDavBackend.php:1068
 OCA\DAV\CalDAV\CalDavBackend->createCalendarObject() at /usr/share/webapps/nextcloud/apps/dav/lib/CalDAV/BirthdayService.php:383
 OCA\DAV\CalDAV\BirthdayService->updateCalendar() at /usr/share/webapps/nextcloud/apps/dav/lib/CalDAV/BirthdayService.php:125
 OCA\DAV\CalDAV\BirthdayService->onCardChanged() at /usr/share/webapps/nextcloud/apps/dav/lib/CalDAV/BirthdayService.php:316
 OCA\DAV\CalDAV\BirthdayService->syncUser() at /usr/share/webapps/nextcloud/apps/dav/lib/Command/SyncBirthdayCalendar.php:93
 OCA\DAV\Command\SyncBirthdayCalendar->execute() at /usr/share/webapps/nextcloud/3rdparty/symfony/console/Command/Command.php:255
 Symfony\Component\Console\Command\Command->run() at /usr/share/webapps/nextcloud/3rdparty/symfony/console/Application.php:915
 Symfony\Component\Console\Application->doRunCommand() at /usr/share/webapps/nextcloud/3rdparty/symfony/console/Application.php:272
 Symfony\Component\Console\Application->doRun() at /usr/share/webapps/nextcloud/3rdparty/symfony/console/Application.php:148
 Symfony\Component\Console\Application->run() at /usr/share/webapps/nextcloud/lib/private/Console/Application.php:214
 OC\Console\Application->run() at /usr/share/webapps/nextcloud/console.php:99
 require_once() at /usr/share/webapps/nextcloud/occ:11

dav:sync-birthday-calendar [<user>]

Unfortunatelly, increasing the verbosity does not give more information. How I can track down the problem?

Thanks
Sven

Have you tried to delete and recreate the birthday calendar?

Agreed, should fix it.

Just delete it from within calendar web app? This didn’t seem to work.

It states that birthday calendar is re-anabled:

Re-enabling birthday calendar for username
Start birthday calendar sync for username

However, the error is the same.

If I’m not wrong, this should happen only if two contacts have same UIDs, or one contact has twice the property birthday, death date or anniversary.

If you don’t have a lot of contacts, check if the contacts app doesn’t suggest to fix some contacts.

Otherwise you can also edit apps/dav/lib/CalDAV/CalDavBackend.php by replacing :

throw new \Sabre\DAV\Exception\BadRequest('Calendar object with uid already exists in this calendar collection.');

with

throw new \Sabre\DAV\Exception\BadRequest('Calendar object with uid '. $extraData['uid'] . ' already exists in this calendar collection.'); 

which will give you the duplicated unique ID when you run sync again. If it ends with -death or -anniversary, remove that part.
Then select carddata from oc_cards where uid = %found_id% shoud give you the VCS data corresponding to the faulty contact.

Thanks, there was indeed two entries with the same uid. Don’t know how this happend.
Thus, I deleted one row.

But now it gets strange: Removing again the birthday calendar and running occ gives the same result with the same uid. Although there is now just one entry in the database…

The card has

ITEM2.X-ABDATE:1983-02-05
ITEM2.X-ABLABEL:Hochzeitstag

Does this give problems?

And it seems to be the only one which has a VALUE parameter:

BDAY;VALUE=DATE:20200325

Other just have

BDAY:20200325

Don’t know if it is of any relevance.

I removed the entry and now everything works as expected.
I don’t know what was the problem, so I post the (anonymized) content of the affected entry. It might help someone finding the root of the cause:

BEGIN:VCARD
VERSION:3.0
UID:af77a365-8a13-4144-9f71-43a631359b77
ADR;TYPE=HOME:;;Street 1;Town;;12345;
EMAIL;TYPE=INTERNET:mail@address
EMAIL;TYPE=HOME:2ndmail@address
FN:Surname\, Name
N:Surname;Name;;Mrs.;
TEL;TYPE=CELL;VALUE=UNKNOWN:+49-123-4567890
ITEM1.URL;VALUE=UNKNOWN:http://www.google.com/profiles/123456789
ITEM2.X-ABDATE:1983-02-05
ITEM1.X-ABLABEL:PROFILE
ITEM2.X-ABLABEL:Hochzeitstag
TEL;TYPE=HOME;VALUE=UNKNOWN:+49-1234-567890
PRODID;VALUE=TEXT:-//dmfs.org//mimedir.vcard//EN
REV;VALUE=DATE-AND-OR-TIME:20200326T155734Z
CATEGORIES:Familie,Telefonbuch
BDAY;VALUE=DATE:20200325
END:VCARD

Thanks for the quick hints, it helped a lot.