fix(submissions): defer translation enqueue to shutdown action#227
Conversation
Move cdcf_enqueue_translations_for_submission() out of the synchronous transition_post_status callback into a deferred shutdown handler. Running the multi-post Polylang group save inline puts our nested wp_insert_post + pll_save_post_translations calls inside Polylang's own save_post chain for the source post and each freshly-inserted draft, where the group save silently fails to persist — same call shape from a REST endpoint outside any post-save chain persists on the first try. Production occurrence 2026-06-16: a public-submission project publish created and worker-translated all 6 language siblings but the Polylang translation group came out empty on every post and the Phase 0 attachment translation siblings were never created. Recovery used /cdcf/v1/link-translations and /cdcf/v1/translate-all, both of which run outside the save chain. Test updated to assert the new contract: the publish hook MUST register a shutdown callback and MUST NOT invoke the enqueue synchronously. Driving the registered callback continues to exercise the (source_id, post_type) dispatch. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesDefer translation enqueue to shutdown hook
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Summary
cdcf_enqueue_translations_for_submission()out of the synchronoustransition_post_statuscallback into a deferredshutdownhandler so ourpll_save_post_translations()call no longer runs inside Polylang's own save_post chain for the source post and each freshly-inserted draft, where the multi-post group save silently fails to persist.cdcf_enqueue_translations_for_submissionmust NOT be invoked synchronously insidetransition_post_status, the hook must register ashutdowncallback, and driving that callback must dispatch with($source_id, $post_type).Production trigger
A public-submission project published 2026-06-16 created and worker-translated all 6 language siblings, but the Polylang translation group came out empty on every post and the Phase 0 attachment translation siblings were never created. Re-running the identical
pll_save_post_translations()call from outside the save chain (via/cdcf/v1/link-translations) persisted on the first attempt — confirming this is a context bug, not a Polylang plugin defect. State on production was recovered manually via/cdcf/v1/link-translations+/cdcf/v1/translate-allon the attachment + per-translationfeatured_mediareassignment + revalidation; this PR closes the underlying gap so the next public-submission publish doesn't repeat the same recovery dance.Test plan
composer test --working-dir=wordpress/themes/cdcf-headless— 578/578 pass, including the updatedtest_publish_hook_defers_enqueue_to_shutdown_for_public_submissioncomposer test --working-dir=wordpress/plugins/cdcf-redis-translations— 30/30 passmainat the "must NOT invoke synchronously" assertion before the fix is appliedgh workflow run deploy.yml -f environment=production, then publish a fresh public-submission project with a featured image and verify (a) the Polylang group is linked across all 6 siblings AND (b) the attachment has 5 language siblings linked🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes