Skip to content

[6.x] Fix saving entries when entryId is posted as a string - #20643

Merged
riasvdv merged 2 commits into
6.xfrom
fix-store-entry-string-id
Nov 12, 2026
Merged

riasvdv merged 2 commits into
6.xfrom
fix-store-entry-string-id

Conversation

@riasvdv

@riasvdv riasvdv commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Description

POST {cpTrigger}/actions/entries/save-entry returned a 500 when entryId arrived as ordinary form data, because the string went straight to Entries::getEntryById(int $entryId):

TypeError: Entries::getEntryById(): Argument #1 ($entryId) must be of type int, string given

StoreEntryController now reads the IDs with $request->integer(), the same way sibling controllers read theirs:

- $entryId = $this->request->input('canonicalId')
-     ?? $this->request->input('sourceId')
-     ?? $this->request->input('entryId');
+ $entryId = $this->request->integer('canonicalId')
+     ?: $this->request->integer('sourceId')
+     ?: $this->request->integer('entryId');

Evidence

StoreEntryControllerTest › "can update an existing entry" now posts entryId as a string, the way a browser form does. The test client had been sending it as an int, so the bug went unnoticed.

  • Before: post(save-entry, ['entryId' => '123', ...]) → 500, TypeError … must be of type int, string given
    After: → redirect, and the entry's title is updated

riasvdv and others added 2 commits November 12, 2026 17:49
StoreEntryController passed entryId from form data straight to
Entries::getEntryById(), which takes an int.
[ci skip]

Amp-Thread-ID: https://ampcode.com/threads/T-01a1d0de-3b65-7450-be5d-d22305f92f01
Co-authored-by: Amp <amp@ampcode.com>
@github-actions

Copy link
Copy Markdown

📚 Storybook previews

@craftcms/ui — open Storybook

No changed components detected in this Storybook.

resources/js — open Storybook

No changed components detected in this Storybook.

@riasvdv
riasvdv merged commit b1c5fe6 into 6.x Nov 12, 2026
@riasvdv
riasvdv deleted the fix-store-entry-string-id branch November 12, 2026 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant