fix: resolve product variation type when the node is a base Post model#1020
Merged
kidunot89 merged 4 commits intoJun 30, 2026
Merged
Conversation
A cart item's variation node can be loaded through the generic post loader (e.g. under Polylang, which doesn't manage the product_variation post-type), arriving as a base \WPGraphQL\Model\Post that has no get_type(). resolve_product_variation_type() then fatals. Fall back to resolving the variation's product type from its ID via wc_get_product() when get_type() isn't callable.
… by the WC email-sent note
Coverage Report for CI Build 28297639419Coverage increased (+0.001%) to 91.801%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
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.
Summary
Post_Types::resolve_product_variation_type()assumes$valueis aProduct_Variationmodel and calls$value->get_type(). When a variation node is loaded through the generic post loader instead — e.g. a cart item'svariation.nodeon a site running Polylang, which doesn't manage theproduct_variationpost-type —$valuearrives as a base\WPGraphQL\Model\Postwith noget_type(), and the resolver fatals (surfacing downstream as "Callback returned incorrect type; expected Promise").This adds a fallback: when
get_type()isn't callable, resolve the variation's product type from its ID viawc_get_product(). The error message also reports the resolved$product_typeinstead of the now-possibly-absent$value->type.Also removes a stray
graphql_debug()left in theProductWithPricingprice resolver.Test plan
cart.contents.nodes[].variation.node) — previously fataled, now resolves the correctProductVariationtype.Product_Variationmodel path — unchanged (still usesget_type()).UserError(now with the resolved type name).