Fix wc-list-orders fatal TypeError on refunds in range (#21) - #22
Merged
Conversation
list_orders() built the wc_get_orders() query without a `type`, so under HPOS the result also contained WC_Order_Refund objects. format_order() is typed \WC_Order and threw a fatal TypeError on the first refund, making wc-list-orders (HTTP 500 / generic MCP error) unusable on any store that had a refund in the queried range. Restrict the query to 'type' => 'shop_order', which excludes refunds and keeps total / max_num_pages honest (a per-row instanceof guard would not). Regression test: OrderManagerTest::test_list_orders_restricts_query_to_shop_order_type (adds a WooCommerce class stub + an arg-capturing wc_get_orders stub). Reproduced and verified end-to-end on WooCommerce 10.8.1 with HPOS. Bump to 1.3.2.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #21.
Problem
wc-list-ordersthrew a fatalTypeError(HTTP 500, surfaced over MCP as a generic error) whenever a refund fell in the queried date range, making the ability unusable on any store that issues refunds:list_orders()built thewc_get_orders()query without atype, so under HPOS the result also containedWC_Order_Refundobjects.format_order()is typed\WC_Orderand rejected the first refund.Fix
Restrict the query to
'type' => 'shop_order'. This excludes refunds and keepstotal/max_num_pageshonest — a per-rowinstanceofguard would stop the fatal but leave the counts (and pagination) wrong.This is the only
wc_get_orders()call site; the report/aggregator code already scopes toshop_ordervia explicit SQL.Tests
tests/Unit/Services/WooCommerce/OrderManagerTest.php— RED before the fix, GREEN after — asserting the query is restricted toshop_order(plus a reusableWooCommerceclass stub and an arg-capturingwc_get_ordersstub in the shared stub file).composer phpcsclean, PHPStan L5 no errors.Verified end-to-end on real WordPress
On the WC 10.8.1 + HPOS test site: created a scratch order + refund, reproduced the exact
TypeErroron the deployed 1.3.1, deployed the fix, confirmedlist_ordersreturns orders with the refund correctly excluded and no fatal, then removed the scratch data.Bumps to 1.3.2 (plugin header + constant,
readme.txtstable tag + changelog,CHANGELOG.md).