Skip to content

Federated calendar sync deletion crashes in CalDavBackend with CachedCalendarObjectDeletedEvent TypeError #61290

Open

Description

@hirschrobert

Steps to reproduce

  1. Run Nextcloud 33.0.5 with at least one federated calendar in oc_calendars_federated.
  2. Let OCA\DAV\BackgroundJob\FederatedCalendarPeriodicSyncJob sync a remote calendar where the sync report contains deleted objects.
  3. The job calls FederatedCalendarSyncService::syncOne(), which calls:
$this->backend->deleteCalendarObject(
    $calendar->getId(),
    $objectUri,
    CalDavBackend::CALENDAR_TYPE_FEDERATED,
    true
);

Expected behaviour

Federated-calendar object deletion should complete without trying to look up a calendar subscription.

Actual behaviour

The background job fails with a TypeError because CalDavBackend::deleteCalendarObject() treats every non-CALENDAR_TYPE_CALENDAR object as a calendar subscription deletion:

if ($calendarType === self::CALENDAR_TYPE_CALENDAR) {
    ...
} else {
    $subscriptionRow = $this->getSubscriptionById($calendarId);

    $this->dispatcher->dispatchTyped(new CachedCalendarObjectDeletedEvent($calendarId, $subscriptionRow, [], $data));
}

For CALENDAR_TYPE_FEDERATED (2), getSubscriptionById($calendarId) returns null, and CachedCalendarObjectDeletedEvent requires an array for $subscriptionData.

Sanitized stack trace excerpt:

Error while running background job OCA\DAV\BackgroundJob\FederatedCalendarPeriodicSyncJob

TypeError: OCA\DAV\Events\CachedCalendarObjectDeletedEvent::__construct():
Argument #2 ($subscriptionData) must be of type array, null given,
called in apps/dav/lib/CalDAV/CalDavBackend.php on line 1588

#0 apps/dav/lib/CalDAV/CalDavBackend.php(1588): OCA\DAV\Events\CachedCalendarObjectDeletedEvent->__construct()
#1 lib/public/AppFramework/Db/TTransactional.php(45): OCA\DAV\CalDAV\CalDavBackend->{closure:...}()
#2 apps/dav/lib/CalDAV/CalDavBackend.php(1564): OCA\DAV\CalDAV\CalDavBackend->atomic()
#3 apps/dav/lib/CalDAV/Federation/FederatedCalendarSyncService.php(122): OCA\DAV\CalDAV\CalDavBackend->deleteCalendarObject()
#4 apps/dav/lib/BackgroundJob/FederatedCalendarPeriodicSyncJob.php(47): OCA\DAV\CalDAV\Federation\FederatedCalendarSyncService->syncOne()
#5 lib/public/BackgroundJob/Job.php(50): OCA\DAV\BackgroundJob\FederatedCalendarPeriodicSyncJob->run()
#6 lib/public/BackgroundJob/TimedJob.php(85): OCP\BackgroundJob\Job->start()
#7 core/Service/CronService.php(176): OCP\BackgroundJob\TimedJob->start()
#8 core/Service/CronService.php(98): OC\Core\Service\CronService->runCli()
#9 cron.php(52): OC\Core\Service\CronService->run()

Diagnosis

This does not appear to be orphaned subscription data in the database. On the affected instance:

calendarobjects grouped by calendartype:
  calendartype=0 count=564
  calendartype=2 count=1210

orphan cached subscription objects:
  calendartype=1 objects without calendarsubscriptions row = 0

federated calendars:
  2 rows in oc_calendars_federated

The error path is therefore the federated delete branch being routed into the cached-subscription event branch.

createCalendarObject() and updateCalendarObject() already distinguish the three cases:

if ($calendarType === self::CALENDAR_TYPE_CALENDAR) {
    ...
} elseif ($calendarType === self::CALENDAR_TYPE_SUBSCRIPTION) {
    ...
} elseif ($calendarType === self::CALENDAR_TYPE_FEDERATED) {
    // TODO: implement custom event for federated calendars
}

deleteCalendarObject() appears to need the same structure.

Suggested fix

Change the delete branch from else to elseif ($calendarType === self::CALENDAR_TYPE_SUBSCRIPTION), and add an explicit no-op CALENDAR_TYPE_FEDERATED branch until there is a dedicated federated-calendar deleted event:

if ($calendarType === self::CALENDAR_TYPE_CALENDAR) {
    $calendarRow = $this->getCalendarById($calendarId);
    $shares = $this->getShares($calendarId);

    $this->dispatcher->dispatchTyped(new CalendarObjectDeletedEvent($calendarId, $calendarRow, $shares, $data));
} elseif ($calendarType === self::CALENDAR_TYPE_SUBSCRIPTION) {
    $subscriptionRow = $this->getSubscriptionById($calendarId);

    $this->dispatcher->dispatchTyped(new CachedCalendarObjectDeletedEvent($calendarId, $subscriptionRow, [], $data));
} elseif ($calendarType === self::CALENDAR_TYPE_FEDERATED) {
    // TODO: implement custom event for federated calendars
}

I tested that local change on the affected instance by forcing the previously failing job with:

occ background-job:execute --force-execute <job-id>

After the local patch, the job completed, the federated sync token advanced, and cached federated objects dropped from 1210 to 1200, indicating that the remote deletions were processed.

Server configuration

  • Nextcloud version: 33.0.5.1 / version string 33.0.5
  • Database: PostgreSQL
  • Background jobs: cron
  • App/code path involved: apps/dav/lib/CalDAV/CalDavBackend.php, apps/dav/lib/CalDAV/Federation/FederatedCalendarSyncService.php, apps/dav/lib/BackgroundJob/FederatedCalendarPeriodicSyncJob.php

Activity

  1. moved this from To triage to Triaged in 🧑‍🤝‍🧑 Community triageon Aug 20, 2026
  2. added theissue type on Nov 6, 2026
  3. ricokulzk-dotcom commented on Nov 21, 2026

    @ricokulzk-dotcom

    Thank you for reporting this issue.

    I can confirm that the same error still occurs on my Nextcloud 35 installation.

    Environment:

    • Nextcloud Server: 35.0.3.2
    • Nextcloud AIO: 15.1.1
    • Database: PostgreSQL
    • DAV app: 2.0.1
    • Installation: Docker on a UGREEN NAS

    Recurring error:

    TypeError:
    OCA\DAV\Events\CachedCalendarObjectDeletedEvent::__construct():
    Argument #2 ($subscriptionData) must be of type array,
    null given
    
    Called in:
    apps/dav/lib/CalDAV/CalDavBackend.php on line 1798
    

    The error occurs repeatedly, approximately every 65 minutes.

    Investigation:

    I inspected the installed Nextcloud source code and confirmed the following:

    In CalDavBackend.php:

    public const CALENDAR_TYPE_CALENDAR = 0;
    public const CALENDAR_TYPE_SUBSCRIPTION = 1;
    public const CALENDAR_TYPE_FEDERATED = 2;

    In deleteCalendarObject(), the current implementation distinguishes only between regular calendars and all other calendar types:

    if ($calendarType === self::CALENDAR_TYPE_CALENDAR) {
        $calendarRow = $this->getCalendarById($calendarId);
        $shares = $this->getShares($calendarId);
    
        $this->dispatcher->dispatchTyped(
            new CalendarObjectDeletedEvent(
                $calendarId,
                $calendarRow,
                $shares,
                $data
            )
        );
    } else {
        $subscriptionRow = $this->getSubscriptionById($calendarId);
    
        $this->dispatcher->dispatchTyped(
            new CachedCalendarObjectDeletedEvent(
                $calendarId,
                $subscriptionRow,
                [],
                $data
            )
        );
    }

    This means that federated calendar objects (CALENDAR_TYPE_FEDERATED = 2) also enter the subscription-specific branch.

    However, getSubscriptionById() returns null when no matching subscription exists.

    I also confirmed that SyncService.php explicitly calls:

    $this->backend->deleteCalendarObject(
        $calendar->getId(),
        $objectUri,
        CalDavBackend::CALENDAR_TYPE_FEDERATED,
        true
    );

    Therefore, deleting a federated calendar object can result in the observed TypeError because the code attempts to retrieve subscription data for a federated calendar.

    Database findings:

    The oc_calendarsubscriptions table contains one subscription (ID 1).

    The oc_calendarobjects table contains:

    • 27 objects with calendartype = 0
    • 0 objects with calendartype = 1
    • 7 objects with calendartype = 2, associated with calendar ID 4

    No orphaned subscription objects were found in the database.

    Conclusion:

    The source code confirms a problematic deletion path for federated calendar objects, consistent with the recurring TypeError. I have not yet conclusively established which scheduled execution triggers each logged occurrence.

    It appears that deleteCalendarObject() needs to distinguish federated calendar objects from subscription objects rather than handling both through the same subscription-specific branch.

    No application code or database records have been modified during this investigation.

    I hope these additional findings help confirm and resolve the issue for Nextcloud 35.

    Best regards!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions