Skip to content

fix(contexts): keep the nodes added by an application update in the loaded shape - #3230

Merged
enjeck merged 2 commits into
mainfrom
fix/noid/context-update-added-node-shape
Nov 25, 2026
Merged

enjeck merged 2 commits into
mainfrom
fix/noid/context-update-added-node-shape

Conversation

@rubenvdlinde

Copy link
Copy Markdown
Contributor

Adding a table or view to an application through PUT /api/2/contexts/{id} logs a PHP warning, Undefined array key "node_type", and the new table doesn't take its place on the start page.

Size: 60 lines: 13 code and 47 tests.

What changes

ContextService::update() keeps the nodes and start page contents of the application in two arrays while it works through the submitted list. The loaded ones come from ContextMapper with snake case keys (node_type, node_id, node_rel_id). Nodes added during the update went in through jsonSerialize(), which uses camel case (nodeType, nodeId, nodeRelId). Ordering the start page afterwards reads the snake case keys, so for an added node it:

  • raised Undefined array key "node_type" and "node_id" for the node, and "node_rel_id" for its start page content,
  • couldn't match the node to its content, so the new content kept order 100 instead of the place it was submitted at,
  • returned an application whose nodes and pages mixed both shapes.

Added nodes and contents now go into those arrays in the same shape the mapper loads them in.

How it was tested

New test in ContextServiceTest: an application with one table gets a view added in front of it. The view comes back in the loaded shape, its start page content gets order 10, and the table moves to 20.

ContextServiceTest without the fix: Undefined array key "node_type" (Tests: 1, Errors: 1)
ContextServiceTest with the fix:    OK (7 tests, 18 assertions)
Full unit suite, PostgreSQL (Nextcloud 34): OK (423 tests, 837 assertions)
php-cs-fixer: no files to fix

🖼️ Screenshots

Backend only, no visual change.

🏁 Checklist

  • ⛑️ Tests (unit and/or integration) are included or not needed
  • 🔙 Backport requests are created or not needed: /backport to stableX.X
  • 📅 Milestone is set
  • 🌸 PR title is meaningful (if it should be in the changelog: is it meaningful to users?)

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@rubenvdlinde
rubenvdlinde marked this pull request as ready for review November 6, 2026 08:25

@AndyScherzinger AndyScherzinger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review focused on performance, security, clean code and architecture (backend only). The checks ran on a dev instance (MariaDB) with #3133 deployed and this commit applied on top, since the PR merges after #3133.

The fix is right: the hand-built arrays match ContextMapper::formatResultRows() key for key and type for type on main and on #3133, a PUT that adds a node logs no "Undefined array key" warning any more, its nodes and pages equal those of the following GET, and the added table takes its place on the start page (an application with table 1 that gets table 2 added now stores orders 10 and 20, where main stored 10 and 10).

Merging after #3133: the service change applies cleanly; the test file conflicts in setUp() in two hunks ($widgetService/$dbConnection against $permissionsService). Both resolve to #3133's side; keeping both declarations of $permissionsService is a fatal "Cannot redeclare".

CI: green.

Comment thread lib/Service/ContextService.php Resolved
Comment thread lib/Service/ContextService.php Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

@rubenvdlinde
rubenvdlinde force-pushed the fix/noid/context-update-added-node-shape branch from 03e55ff to 9eb9d29 Compare November 21, 2026 10:54
@rubenvdlinde

Copy link
Copy Markdown
Contributor Author

/backport to stable2

@backportbot backportbot Bot added the backport-request Pending backport by the backport-bot label Nov 22, 2026
@rubenvdlinde

Copy link
Copy Markdown
Contributor Author

The shared formatter for nodes and page contents is now #3345.

@blizzz

blizzz commented Nov 24, 2026

Copy link
Copy Markdown
Member

please resolve the conflicts

@blizzz blizzz added the 2. developing Work in progress label Nov 24, 2026
…oaded shape

Updating an application with new tables or views stored the added nodes and start page
contents in their JSON shape (nodeType, nodeId, nodeRelId) next to the loaded ones
(node_type, node_id, node_rel_id). Ordering the start page then read keys that were not
there, which raised an "Undefined array key" warning and left the new contents
unordered, and the returned application mixed both shapes.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
Added nodes are inserted at their final order, so the reorder after
them no longer rewrites their content. A node without an order keeps
its position in the list. The tests record the orders written to the
database.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Ruben van der Linde <ruben@conduction.nl>
@enjeck
enjeck force-pushed the fix/noid/context-update-added-node-shape branch from 9eb9d29 to 7b15be9 Compare November 25, 2026 06:08
@enjeck
enjeck merged commit 385a8c3 into main Nov 25, 2026
75 checks passed
@enjeck
enjeck deleted the fix/noid/context-update-added-node-shape branch November 25, 2026 06:44
@backportbot backportbot Bot removed the backport-request Pending backport by the backport-bot label Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2. developing Work in progress AI assisted bug Something isn't working feedback-requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants