Skip to content

Fix sync loop flagging PDFs and other files without dimensions - #1401

Open
gabrielcld2 wants to merge 1 commit into
developfrom
fix/1397-non-image-sync-loop
Open

gabrielcld2 wants to merge 1 commit into
developfrom
fix/1397-non-image-sync-loop

Conversation

@gabrielcld2

Copy link
Copy Markdown
Collaborator

Fixes #1397

Approach

Since 3.3.9, files without width and height (PDF, audio, documents) uploaded in the admin get the sync error Sync loop detected: the "delivery" sync state could not be saved. and never sync to Cloudinary.

Preparing the sync of such a file asks for its URL, because no sized URL exists for it. In the admin, the attachment URL filter calls back into Media::cloudinary_id(), which prepared the sync again. That nesting used to stop because Utils::is_saving_metadata() checked did_action(). #1303 changed it to doing_action(), so the nesting continued until the loop guard from #1328 stopped it and saved the error.

  • Media::cloudinary_id() now caches a placeholder for the attachment before it prepares the sync. A nested call during preparation gets the local URL instead of preparing the sync again. The outer call then replaces the placeholder with the real ID.
  • On upgrade from 3.3.9, Sync::clear_delivery_loop_errors() removes that exact error, in English and in every installed language, so the affected files sync again. It doesn't touch other sync errors, or loop errors on other sync types.
  • The loop error message moved to Sync::get_loop_error_message(), so the guard and the cleanup use the same string.

QA notes

  1. With auto sync on, upload a PDF from Media > Add New.
  2. Confirm the attachment shows no sync error and syncs to Cloudinary, with a res.cloudinary.com URL.
  3. Repeat with an MP3 file and a DOCX file.
  4. Upgrade path: on a 3.3.9 site with an errored PDF, update to this build. The error clears and the PDF syncs.

Automated:

  • New PHPUnit tests in test-media-cloudinary-id-reentry.php (6 tests). The 2 regression tests fail without the fix. The full suite passes.
  • New e2e spec cloudinary-document-sync.spec.js uploads a PDF through the Media Library. The other specs upload through REST, which skips the sync preparation, so they can't catch this. This spec fails without the fix, with the same error the customer reported.

Files without width and height (PDF, audio, documents) got the error
'Sync loop detected: the "delivery" sync state could not be saved.'
when uploaded in the admin. Preparing their sync asks for the
attachment URL, and the admin URL filter called back into
Media::cloudinary_id(), which prepared the sync again until the loop
guard tripped.

Answer that nested call with the local URL instead. On upgrade from
3.3.9, clear the delivery loop errors it flagged so those files sync.

Adds PHPUnit regression tests and an e2e test that uploads a PDF
through the Media Library.

Fixes #1397

This branch has not been deployed

No deployments
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.

2 participants