[5.x]: `ElementsController::actionSaveDraft()` clones and validates the *stored* canonical before it applies the posted form values:
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
Research direction
Start in ElementsController::actionSaveDraft(), comparing createDraft() at line 2028 with _applyParamsToElement() at line 2036 and saveElement() at line 2052; review actionSave() at line 1418 as the working comparison. Confirm the draft path validates the submitted corrected values, and verify that autosave succeeds when the stored value is invalid but the posted value is valid.
Written by the indexing model from the issue text.
Description
What happened?
Description
ElementsController::actionSaveDraft() clones and validates the stored canonical before it
applies the posted form values:
| Step | Line (5.11.3) |
|---|---|
createDraft() — clones and validates the canonical |
2028 |
_applyParamsToElement() — applies what the author typed |
2036 |
saveElement() — validates again, now with the author's input |
2052 |
If the stored element no longer validates, the first validation fails every time, regardless of
what the author submits. Correcting the offending value in the editor does not help, because
the correction is only applied after the failure. The entry becomes uneditable through the
element editor.
actionSave() (1418) does not go through createDraft() and therefore still works — but an
author has no way of knowing that the Save button is the way out.
Steps to reproduce
- Add a Plain Text field with no character limit to a section, and save an entry with a long
value in it. - In Settings → Fields, set the field's character limit below that value.
- Open the entry and shorten the value to something valid.
- Wait for the autosave.
Expected behavior
The submitted, corrected value is validated, and the draft saves.
Actual behavior
The autosave keeps failing on the old, stored value. The only ways out are the Save button
(which bypasses draft creation) or changing the data outside the control panel.
Combined with the swallowed exception described in the companion issue, the author sees only
"A server error occurred" and has no indication which field is at fault or that Save would work.
Related
- #4958 — reported in 2019, with the correct diagnosis from the reporter: "If we tried to
shorten that value via the CP form and save the entry, the same error occurs — maybe because
it is trying to save a copy of the entry in its original state?" Confirmed again in 2020
("I can't save that entry, even if the new value is shorter"), then closed by referral to the
Feed Me repo. At the time this was the revision path in Craft 3; in Craft 5 the same shape
lives increateDraft().
Craft CMS version
5.11.3
PHP version
8.4
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
- Dominant language
- PHP
- Stars
- 3.6k
- Forks
- 705
- Avg merge
- 15h 41m
- Merged PRs (30d)
- 211
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from craftcms/cms
-
bug repo:cms
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
craftcms/cms#19828 · 1 comment ·
Maintainers usually reply within 1 day
-
bug repo:cms
Difficulty 4/5 3-5 days Newbie friendliness 50/100
craftcms/cms#19829 · 1 comment ·
Maintainers usually reply within 1 day
-
bug repo:cms
Difficulty 3/5 1-2 days Newbie friendliness 68/100
craftcms/cms#19809 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 5/5 Over a week Newbie friendliness 25/100
craftcms/cms#19761 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 68/100
craftcms/cms#19214 · 4 comments ·
Maintainers usually reply within 1 day
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
awslabs/aidlc-workflows#1879 ·
Maintainers usually reply within 1 day
-
bug customer-reported
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
MagnaCapax/PMSS#1011 ·
Maintainers usually reply within 5 days
-
Talk Review
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
socallinuxexpo/scale-drupal#351 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
code4romania/cpc#47 ·
Maintainers usually reply within 1 day
-
Bug Status: Needs Triage
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day