Skip to content

DirectEditing Manager::getTemplates() crashes when a creator returns ATemplate objects (per interface contract) #64461

Open

Description

@IoSonoPiero

Steps to reproduce

  1. Server on Nextcloud 34.0.4.1 with richdocuments 11.1.1 (implements OCP\DirectEditing\ACreateFromTemplate and follows PR feat(direct-editing): integrate with OCP\DirectEditing API richdocuments#5656, "integrate with OCP\DirectEditing API").
  2. From the Nextcloud Android app (v35.0.0), tap "+" → "New document" (or spreadsheet).
  3. App calls GET /ocs/v2.php/apps/files/api/v1/directEditing/templates/richdocuments/document (and /spreadsheet).

Expected behaviour

Template list is returned, template picker opens.

Actual behaviour

500 error, request fails every time, for every creator type (document, spreadsheet — both tested). Exception in nextcloud.log:

Cannot use object of type OCA\Richdocuments\DirectEditing\OfficeTemplate as array in file
'/var/www/html/lib/private/DirectEditing/Manager.php' line 91

Root cause

OCP\DirectEditing\ACreateFromTemplate::getTemplates() is documented to return ATemplate[]:
https://github.com/nextcloud/server/blob/v34.0.4/lib/public/DirectEditing/ACreateFromTemplate.php

richdocuments' AbstractOfficeCreator::getTemplates() follows this literally and returns an array of OfficeTemplate objects (extending ATemplate):
https://github.com/nextcloud/richdocuments/blob/v11.1.1/lib/DirectEditing/AbstractOfficeCreator.php#L67-L75

But OC\DirectEditing\Manager::getTemplates() (private) treats each element as a plain associative array, not an object:

$templates = array_map(function ($template) use ($creator) {
    $template['extension'] = $creator->getExtension();
    $template['mimetype'] = $creator->getMimetype();
    return $template;
}, $templates);

https://github.com/nextcloud/server/blob/v34.0.4/lib/private/DirectEditing/Manager.php#L75-L96

This array-mutation code appears unchanged since at least Nextcloud 30 (checked v30.0.0 tag, identical logic), so it silently relied on apps returning raw arrays despite the interface declaring ATemplate[] since 18.0.0. Any app that follows the documented contract literally (as richdocuments now does, after its recent OCP\DirectEditing refactor) breaks this code with a fatal error.

Fix suggestion

Manager::getTemplates() should call $template->jsonSerialize() (or equivalent) before mutating, since ATemplate implements JsonSerializable and already exposes id/title/preview via jsonSerialize():
https://github.com/nextcloud/server/blob/v34.0.4/lib/public/DirectEditing/ATemplate.php

Environment

  • Nextcloud 34.0.4.1
  • richdocuments 11.1.1
  • Nextcloud Android app 35.0.0
  • Reproduced with both document and spreadsheet creator types

Activity

  1. moved this from To triage to In progress in 🧑‍🤝‍🧑 Community triageon Sep 17, 2026
  2. icewind1991 commented on Sep 17, 2026

    @icewind1991
    Member

    Thanks for the report and finding the root cause, fix is here: #64494

  3. jim-sang commented on Oct 22, 2026

    @jim-sang

    Independent confirmation on the current stable branch, plus one detail that may explain why this is only reported occasionally.

    Reproducible on 35.0.2.2 (not only 34.x)

    • Nextcloud 35.0.2.2 (stable channel), PHP 8.4.27, nginx 1.26.3, MariaDB 11.8
    • richdocuments 12.0.1 (current latest release)
    • Client: Nextcloud iOS 35.0.0 → "+ → New document"; the same 500 also happens from the web UI "New" menu
    • Cannot use object of type OCA\Richdocuments\DirectEditing\OfficeTemplate as array in .../lib/private/DirectEditing/Manager.php:91

    Trigger condition: it only crashes when the creator actually has templates.
    Manager::getTemplates() replaces the default ['empty' => ...] with $creator->getTemplates() and then maps over it. When that returns [] (no files in the user's Templates/, no system template directory configured), the array_map callback never runs and nothing fails. As soon as a single template exists, every call to /ocs/v2.php/apps/files/api/v1/directEditing/templates/{editorId}/{creatorId} returns 500.
    On my instance some accounts have 25–45 files in Templates/ and fail 100% of the time, while accounts with an empty Templates/ are unaffected — which makes the bug look client- or user-specific.

    Still present on master (checked 2026-10-22): Manager.php:91-92 still indexes the elements as arrays, while ACreateFromTemplate::getTemplates() is documented as @return ATemplate[] and richdocuments returns exactly that (AbstractOfficeCreator::getTemplates() → new OfficeTemplate(...)). The app is compliant, the server is the side violating the contract.

    The fix in #64494 looks exactly right (object → jsonSerialize(), array path preserved). It has had no review since 2026-09-17 and the backport requests to stable33/34/35 are still unaddressed. Is anything missing to get it merged — e.g. a regression test? Happy to help with a unit test if that is the blocker.

    Impact worth noting: besides the template picker being unusable, each failed attempt writes an error to nextcloud.log, which then surfaces in the admin "Errors in the log" setup check — so a pure code defect keeps re-raising a server-health warning.

  4. reef2009 commented on Oct 25, 2026

    @reef2009

    Still reproducible on current releases.

    • Nextcloud server 35.0.2.2 (official Docker image nextcloud:35, latest 35.x tag)
    • richdocuments 12.0.1 (no newer version offered by occ app:update --showonly)
    • Collabora CODE 26.04.5.2.1
    • Nextcloud Android app 35.0.1

    Request: GET /ocs/v2.php/apps/files/api/v1/directEditing/templates/richdocuments/spreadsheet?format=json

    Log: "Cannot use object of type OCA\Richdocuments\DirectEditing\OfficeTemplate as array in file '/var/www/html/lib/private/DirectEditing/Manager.php' line 91"

    The app shows "Fout bij ophalen sjablonen" (error fetching templates) when creating a new spreadsheet, both in my own folder and in a Team folder.

    Creating the same file type from the web interface works. Opening and saving existing documents also works.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions