WordPress.org

Make WordPress Core

Opened 4 months ago

Closed 4 months ago

Last modified 4 months ago

#48472 closed defect (bug) (fixed)

The "wp_generate_attachment_metadata" filter is not fired when the initial upload request fails but the upload was completed successfully by retrying to create image sub-sizes

Reported by: azaozz Owned by: azaozz
Milestone: 5.3 Priority: normal
Severity: normal Version: 5.3
Component: Upload Keywords: has-patch needs-testing 2nd-opinion fixed-major
Focuses: Cc:

Description

After #47872 it became possible to successfully complete an uploaded image post-processing even when the initial upload request resulted in a server error/PHP running out of resources.

However when that happens the wp_generate_attachment_metadata filter is never reached and is not fired as expected. As this is the de-facto "upload is now completed successfully" hook, it causes problems in both updating/filtering the metadata on successful uploads and when using it to trigger additional post-processing.

Attachments (1)

48472.diff (3.1 KB) - added by azaozz 4 months ago.

Download all attachments as: .zip

Change History (10)

#1 @azaozz
4 months ago

  • Milestone changed from Awaiting Review to 5.3

Moving to 5.3 for consideration.

There was a discussion and several regression reports in #core-media on Slack.

The consensus was that a hook needs to be fired after an image is uploaded successfully and all sub-sizes were created. Before #47872 wp_generate_attachment_metadata was always fired in these cases. Firing it at the end of wp_update_image_subsizes() (when new metadta was generated and additional image sub-sizes created) seems to make the most sense and is backwards compatible.

Last edited 4 months ago by azaozz (previous) (diff)

@azaozz
4 months ago

#2 @azaozz
4 months ago

In 48472.diff:

  • Run the wp_generate_attachment_metadata filter at the end in wp_update_image_subsizes() when new metadata was generated and additional image sub-sizes were created. This ensures consistent behavior with earlier WP versions.
  • Add another arg in the wp_generate_attachment_metadata filter to add context.
  • Fix some inline docs and ensure the new image meta is always saved before starting post-processing.
Last edited 4 months ago by azaozz (previous) (diff)

#3 @azaozz
4 months ago

  • Keywords has-patch needs-testing 2nd-opinion added

For easier testing thinking to commit this to trunk (5.4) now. Backporting to the 5.3 branch will ideally happen in couple of days, after more testing/review/second opinion.

#4 @azaozz
4 months ago

  • Owner set to azaozz
  • Resolution set to fixed
  • Status changed from new to closed

In 46621:

Upload:

  • Run the wp_generate_attachment_metadata filter at the end in wp_update_image_subsizes() when new metadata was generated and additional image sub-sizes were created.
  • Add another arg in the wp_generate_attachment_metadata filter for additional context.
  • Fix inline docs and ensure the new image meta is always saved before starting post-processing.

Fixes #48472 for trunk.

#5 @azaozz
4 months ago

  • Keywords fixed-major added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopen for merging to the 5.3 branch.

#6 @SergeyBiryukov
4 months ago

In 46622:

Docs: Add @since tag for the $context parameter added to wp_generate_attachment_metadata filter in [46621].

See #48472.

#7 @azaozz
4 months ago

In 46651:

Upload: Ensure the new image meta is always saved before starting post-processing of an uploaded image, even if there was an error while scaling or rotating it.

See #48472.

#8 @azaozz
4 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 46655:

Upload:

  • Run the wp_generate_attachment_metadata filter at the end in wp_update_image_subsizes() when new metadata was generated and additional image sub-sizes were created.
  • Add another arg in the wp_generate_attachment_metadata filter for additional context.
  • Fix inline docs and ensure the new image meta is always saved before starting image post-processing.

Props SergeyBiryukov, azaozz.
Merges [46621], [46622], and [46651] to the 5.3 branch.
Fixes #48472.

This ticket was mentioned in Slack in #core-media by mike. View the logs.


4 months ago

Note: See TracTickets for help on using tickets.