Fix CartAddressInput.telephone hardcoded as required regardless of store configuration - #41067
Conversation
When the store is configured with Telephone = Optional (Stores > Config > Customers > Customer Configuration > Name and Address Options > Show Telephone), calling setShippingAddressesOnCart or setBillingAddressOnCart without a telephone field fails at the GraphQL schema level with '"telephone" of required type "String!" was not provided', ignoring the store configuration entirely. Root cause: commit 86ecde0 (ACP2E-4223) changed telephone in CartAddressInput from `String` to `String!` as a side effect of REST API validation improvements. The schema-level NonNull constraint is enforced by the GraphQL framework before any resolver or business-logic validation runs. Fix: revert CartAddressInput.telephone to `String` (nullable). Server- side validation through Quote\Address::validate() already respects the store configuration via the customer_address EAV attribute is_required flag, so no additional resolver change is needed. Fixes magento#41034
|
Hi @koushikch7. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
|
@magento run all tests |
|
@magento run all tests |
|
@magento run Unit Tests |
WebAPI Tests AnalysisI've investigated the WebAPI Tests failure in detail by examining the Allure report data directly. Result: the failure is pre-existing infrastructure noise, not caused by this PR.
The single B2B failure is:
This is an async order status test in the B2B suite with Local VerificationI also verified the fix against a running Magento 2.4 instance:
Schema introspection confirms The fix is minimal, correct, and backward-compatible. No existing tests are broken by this change. |
|
@magento run WebAPI Tests |
Description (*)
When the store is configured with Telephone = Optional
(Stores → Configuration → Customers → Customer Configuration → Name and Address Options → Show Telephone = Optional),
calling
setShippingAddressesOnCartorsetBillingAddressOnCartwithout atelephonefield fails at the GraphQL layer:This error is thrown by the GraphQL framework before any resolver or business-logic validation runs, making the store configuration completely ineffective.
Root cause: Commit
86ecde063c94(ACP2E-4223, Improved validation for REST API) changedCartAddressInput.telephonefromStringtoString!as a side effect. The NonNull constraint in the schema is enforced at the GraphQL protocol level, bypassing the server-side config-aware validation inQuote\Address::validate().Fix: Revert
CartAddressInput.telephonetoString(nullable). Server-side enforcement of telephone when the store configures it as Required is already handled byQuote\Address::validate()→compositeValidator→ EAV attributeis_requiredflag oncustomer_address.telephone. No additional resolver change is needed.Fixed Issues (if relevant)
Manual testing scenarios (*)
When telephone is Optional (Stores → Config → Customers → Customer Configuration → Name and Address Options → Show Telephone = Optional):
setShippingAddressesOnCartwithout atelephonefield:Expected: Address set successfully.
Before fix:
"telephone" of required type "String!" was not provided.After fix: Address is accepted; telephone absent is valid when configured as Optional.
telephoneis correctly rejected by server-side validation with a meaningful error.Impact assessment
CartAddressInputis used by bothsetShippingAddressesOnCartandsetBillingAddressOnCart. Both mutations benefit from this fix.ValidateAddressFromSchema(used in output resolversShippingAddressesandBillingAddress) correctly treatstelephoneas optional since it now readsStringfrom the schema — saved addresses without telephone are returned rather than silently nulled.String!fields inCartAddressInputare affected.CartAddressInterface.telephone: String) was already nullable and is unchanged.Contribution checklist (*)
ValidateAddressFromSchemaTest— 4 test cases covering nullable/NonNull field scenarios)