Repository navigation
Fix fatal generating receipt when variation parent product was deleted - #68369
jorgeatorres merged 6 commits into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughReceipt rendering now handles variation items whose parent product was deleted. It falls back to the order line item name and adds regression coverage and a patch changelog entry. ChangesReceipt Rendering Fix
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to Receipt rendering now safely uses the order line item name when a variation’s deleted parent cannot be resolved, preventing receipt-generation failures for affected historical orders. The regression coverage is in place and no current merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 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 |
Testing GuidelinesHi , Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed. Reminder: PR reviewers are required to document testing performed. This includes:
|
jorgeatorres
left a comment
There was a problem hiding this comment.
Thanks for the PR @soroush5. Even though this is an edge-case, I think it's worth fixing.
That said, there are problems here that local minimal local verification would have caught: the testing steps don't reproduce the fatal at all, the new unit test also passes without the fix, and linting has failed twice in CI rather than being caught locally. Verifying your changes before submitting is part of the contribution, and it's what keeps review time focused on the fix itself. "Leaving to CI" is not the way to go.
I've noticed you've opened a few more PRs, and we appreciate that you want to contribute. Please give all of them the same treatment before requesting review: reproduce the issue yourself, make sure the test fails without the fix and passes with it, and confirm lint and tests pass locally. We're leaving this one open so you can do that work, but if it comes back for review in the same state, we'll have to close it.
|
You're right on all three, and I did the work locally this time instead of leaving it to CI.
On the other PRs: point taken — same treatment (reproduce locally, red/green test, local lint) before requesting review. |
jorgeatorres
left a comment
There was a problem hiding this comment.
@soroush5: asking the reviewer to run unit tests is not the same as testing instructions. We need to be able to reproduce both the bug and ensure the fix is correct.
I assume if you reported the issue and opened the PR it's because this can indeed occur somehow, even if it's an edge case. Please provide instructions anyone can follow, even if they require modifying the database or running a PHP snippet or WP-CLI command to simulate a broken state. Similarly, indicate all necessary steps to generate the receipt via the REST endpoint to illustrate the fix.
|
Fair point — "run the unit test" isn't testing instructions. Rewrote the section as a real end-to-end repro, all verified live on wp-env (PHP 8.1), not assumed:
No UI click path can build the orphan (trash cascades), which is why step 1 goes straight to the row level — the same shape as failed cleanups and out-of-band deletes. The automated test stays as backup (errors without the fix, 17/17 green with it). |
jorgeatorres
left a comment
There was a problem hiding this comment.
Hi @soroush5! Overall this looks good to me. Left some minor feedback.
I don't think the testing instructions are ideal yet but I won't block on that. Just for future reference: a snippet of code creating the products and even the order is not too different from a unit test. The idea with these steps is that anyone can easily follow those, and at least for the first part products can be created via the admin and the order as well. Deleting the parent does require WP-CLI or manipulating the database, but that can also be explained.
jorgeatorres
left a comment
There was a problem hiding this comment.
LGTM. Thank you @soroush5!
Submission Review Guidelines:
Changes proposed in this Pull Request:
Closes #68368.
ReceiptRenderingEnginecalled->get_name()on the result ofwc_get_product( parent_id )with no guard. When the parent variable product was deleted the factory returnsfalseand receipt generation fatals. Now falls back to the line item name, mirroring the existingfalsebranch for a missing item product.How to test the changes in this Pull Request:
End-to-end via the REST receipt endpoint (verified live on wp-env, PHP 8.1 — not just the unit test):
wp eval-file). This creates a variable product + variation + order, then deletes ONLY the parent row — the same shape as failed cleanups / out-of-band deletes (deleting from the UI cascades to variations, so no click path can build this):It prints something like
order_id=14 parent lookup: falsewhile the variation stays readable.2. Make an admin Application Password (Users → Profile → Application Passwords, or
wp user application-password create admin repro --porcelain).3. Generate the receipt through REST:
(If permalinks are plain, use
index.php?rest_route=/wc/v3/orders/<order_id>/receipt&force_new=1instead.)Error: Call to a member function get_name() on bool).{"receipt_url": "...", "expiration_date": "..."}.pnpm test:php:env -- --filter test_generate_receipt_falls_back_to_item_name_when_variation_parent_is_deleted(errors without the fix, passes with it; fullReceiptRenderingEngineTestclass 17/17 green).Testing that has already taken place:
wp-env locally (PHP 8.1): new test ERRORS without the fix (
Call to a member function get_name() on bool) and passes with it; fullReceiptRenderingEngineTestclass 17/17 green;phpcs-changedon the branch diff clean;php -lclean on both files.Milestone