nextcloud / nextcloud/server

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

Open Beginner friendly
#64,461 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

3. to review
Dominant language
PHP
Stars
36.9k
Forks
5.2k
Avg merge
2d 3h
Merged PRs (30d)
713

Description

Steps to reproduce
  1. Server on Nextcloud 34.0.4.1 with richdocuments 11.1.1 (implements OCP\DirectEditing\ACreateFromTemplate and follows PR https://github.com/nextcloud/richdocuments/pull/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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/private/DirectEditing/Manager.php, especially getTemplates(), and compare its handling with lib/public/DirectEditing/ATemplate.php and the ACreateFromTemplate contract. Reproduce the GET directEditing templates request for document or spreadsheet. Done means creators returning ATemplate objects no longer cause a 500 and the template list includes the expected fields.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.