Deprecated `columns` payload on PUT /api/1/views/{viewId} always returns 500

Open Beginner friendly
#3,208 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

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

Research direction

Start in lib/Model/ViewUpdateInput.php around lines 90-113, where the deprecated columns branch calls json_encode() and passes the resulting string to ColumnSettings::createViewSettingsFromInputArray() in lib/Model/ColumnSettings.php, which expects an array. Reproduce with the curl PUT in the issue, then check whether the ViewColumnInformation list needs normalising to plain arrays. Done when that request updates the view's columns instead of returning 500, and the new format still works.

Written by the indexing model from the issue text.

Description

Steps to reproduce

PUT /index.php/apps/tables/api/1/views/{viewId} with the deprecated columns payload, i.e. a plain list of column ids and no columnSettings key:

curl -u user:pass -H 'OCS-APIRequest: true' -H 'Content-Type: application/json' \
  -X PUT 'http://localhost/index.php/apps/tables/api/1/views/357' \
  -d '{"data":{"columns":[1142,1143,1144,1145]}}'
Expected behavior

The view's columns are updated, since columns is documented as the deprecated-but-supported form — ViewUpdateInput::fromInputArray() logs The old columns format is deprecated. Please use the new format with columnId and order properties. and then converts it. Failing that, a 400 Bad Request naming the problem.

Actual behavior

500 Internal Server Error, with an HTML error page rather than a JSON body. nextcloud.log:

OCA\Tables\Model\ColumnSettings::createViewSettingsFromInputArray(): Argument #1 ($inputColumnSettings)
must be of type array, string given, called in lib/Model/ViewUpdateInput.php on line 113
in file 'lib/Model/ColumnSettings.php' line 63

The conversion branch builds a ViewColumnInformation[] and then JSON-encodes it into a string (lib/Model/ViewUpdateInput.php:92-103):

$value = [];
foreach ($data['columns'] as $order => $columnId) {
    $value[] = new ViewColumnInformation($columnId, order: $order);
}
$value = json_encode($value);   // <- string

$data['columnSettings'] = $value;

and line 113 passes that string straight into a parameter typed array:

columnSettings: isset($data['columnSettings']) ? ColumnSettings::createViewSettingsFromInputArray($data['columnSettings'], $columnsMap) : null,

transformJsonToArrayInPayload(), which would decode a JSON string back into an array, runs at line 90 — before the string is produced — so it never sees this value. The deprecated path therefore cannot succeed: it throws a TypeError for every input.

Dropping the json_encode() call (keeping $value as the array it already is) is enough to make the branch work, since ColumnSettings::createViewSettingsFromInputArray() accepts exactly that shape. A ViewColumnInformation object list may still need normalising to plain arrays depending on what that method expects.

Introduced in cff2c94a ("refactor(Views): turn some details into objects with early validation", 2025-12-05), so every release from v2.0.0 onwards is affected, including current main.

Tables app version

main (reproduced at 4150d63b), also present in every tag from v2.0.0 onwards

Server operating system / environment

Nextcloud 36.0.0 dev, PHP 8.5, MySQL — nextcloud-docker-dev

Additional info

Found while seeding test data through the API; the frontend sends columnSettings and so never hits this path, which is presumably why it has gone unnoticed.

Dominant language
JavaScript
Stars
220
Forks
55
Avg merge
1d 6h
Merged PRs (30d)
79

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

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.

More from nextcloud/tables

All issues in nextcloud/tables

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.