New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent backup post from being deleted when HPOS is authoritative #45330
Conversation
Test Results SummaryCommit SHA: 2a39b3b
To view the full API test report, click here. To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
Hi @coreymckrill, Apart from reviewing the code changes, please make sure to review the testing instructions as well. You can follow this guide to find out what good testing instructions should look like: |
1 similar comment
Hi @coreymckrill, Apart from reviewing the code changes, please make sure to review the testing instructions as well. You can follow this guide to find out what good testing instructions should look like: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Looks good, tests well. I also tried deleting some non-order posts to make sure this filter doesn't cause disruption for other post types.
…5330) This PR short-circuits wp_delete_post() so that when HPOS is authoritative, any attempts to delete the backup post are not successful (which could also end up deleting the HPOS order). This only applies to non placeholder posts, as placeholder posts won't trigger the cascade of operations that might be problematic here. Fixes #42746
Submission Review Guidelines:
Changes proposed in this Pull Request:
When HPOS is authoritative, calling
wp_delete_post()
on a backup post also removes the HPOS order. By default, this shouldn't happen, but it can happen when, for example, sync is temporarily disabled and the backup post is kept in the trash, which will get autoremoved once WP empties the trash (and thus also deleting the HPOS order).There are other implications as a few caches and stats are updated when an order is removed, and a post with
shop_order
as type would trigger this even when HPOS is set as datastore and the "true" order hasn't been deleted.While those are some edge cases, they could happen. This PR short-circuits
wp_delete_post()
so that when HPOS is authoritative, any attempts to delete the backup post are not successful. This only applies to non placeholder posts, as placeholder posts won't trigger the cascade of operations that might be problematic here.It's worth mentioning that our sync code doesn't consider missing backup posts as truly missing and will let you switch datastores freely, which can result in an incorrect "view" of the orders on your site. That's addressed in #45332, but this PR will at least make sure that can't happen again.
Closes #42746.
How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
wp eval "wp_delete_post( <ORDER_ID> );"
.wp eval "wp_delete_post( <ORDER_ID> );"
again and confirm that the order has been removed, and also from the HPOS tables (and stats table):Changelog entry
Significance
Type
Message
Comment