Opened 4 weeks ago
Closed 4 weeks ago
#66056 closed defect (bug) (fixed)
Media: prepare the attachment finalize response from the current post row
| Reported by: | adamsilverstein | Owned by: | adamsilverstein |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.1.1 |
| Component: | Media | Version: | 7.1 |
| Severity: | normal | Keywords: | has-patch has-unit-tests dev-reviewed |
| Cc: | Focuses: |
Description
Follow up to the client-side media processing endpoints (the sideload and finalize routes on WP_REST_Attachments_Controller), needed alongside the Gutenberg package update planned for 7.1.1.
Claude wrote this one up after working through the Gutenberg side:
finalize_item()fetches the attachment post at the top of the method, then applies thewp_generate_attachment_metadatafilter and writes the metadata, and finally prepares its response from the$postit fetched at the start. Anything a callback on that filter writes to the attachment's post row - an optimizer changingpost_mime_typeonce it has converted the file, for instance - is missing from the response.
That mattered less while the editor threw the finalize response away and refetched the attachment. With https://github.com/WordPress/gutenberg/pull/81947 the editor stores the finalize response as its copy of the attachment record and no longer refetches, so whatever the response carries is what the block keeps for the session. That change fixes https://github.com/WordPress/gutenberg/issues/81844, where a URL-keyed host cache answered the refetch with the pre-finalize record and the Image block lost its Resolution control, and it is a candidate for the 7.1.1 package update. The server side needs to land with it.
The fix is small: re-read the post with
$this->get_post()after the metadata is written and prepare the response from that. When the re-read fails, because a callback rejected the file and deleted the attachment, return theWP_Errorrather than a 200 built from the stale row, so the editor reports the upload as failed instead of storing a record for an attachment that is gone.
Three unit tests cover the finalize response carrying the generated sub-sizes, reflecting a post row rewritten by the filter, and failing when the attachment was deleted.
PR incoming.
Change History (9)
This ticket was mentioned in PR #13412 on WordPress/wordpress-develop by @adamsilverstein.
4 weeks ago
#1
This ticket was mentioned in Slack in #core by adamsilverstein. View the logs.
4 weeks ago
This ticket was mentioned in Slack in #core by adrianduffell. View the logs.
4 weeks ago
#6
@
4 weeks ago
- Keywords dev-feedback added
- Resolution fixed
- Status closed → reopened
Reopening to consider for the 7.1 branch.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Companion to https://github.com/WordPress/gutenberg/pull/81947, which fixes https://github.com/WordPress/gutenberg/issues/81844 and is a candidate for the 7.1.1 package update. Both halves need to ship together.
_Claude did the port and the write-up:_
## AI Use
Code and description both written with 🤖 Claude Code. I will review and test.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Ga8xRGdztewVMVJ1rZpUJw