Skip to content

Fix CartAddressInput.telephone hardcoded as required regardless of store configuration - #41067

Open
koushikch7 wants to merge 2 commits into
magento:2.4-developfrom
koushikch7:fix/issue-41034-cart-address-telephone-optional
Open

Fix CartAddressInput.telephone hardcoded as required regardless of store configuration#41067
koushikch7 wants to merge 2 commits into
magento:2.4-developfrom
koushikch7:fix/issue-41034-cart-address-telephone-optional

Conversation

@koushikch7

Copy link
Copy Markdown

Description (*)

When the store is configured with Telephone = Optional
(Stores → Configuration → Customers → Customer Configuration → Name and Address Options → Show Telephone = Optional),
calling setShippingAddressesOnCart or setBillingAddressOnCart without a telephone field fails at the GraphQL layer:

"telephone" of required type "String!" was not provided.

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) changed CartAddressInput.telephone from String to String! as a side effect. The NonNull constraint in the schema is enforced at the GraphQL protocol level, bypassing the server-side config-aware validation in Quote\Address::validate().

Fix: Revert CartAddressInput.telephone to String (nullable). Server-side enforcement of telephone when the store configures it as Required is already handled by Quote\Address::validate()compositeValidator → EAV attribute is_required flag on customer_address.telephone. No additional resolver change is needed.

Fixed Issues (if relevant)

  1. Fixes GraphQL: CartAddressInput.telephone is required in 2.4.9 even when Telephone is configured as Optional #41034

Manual testing scenarios (*)

When telephone is Optional (Stores → Config → Customers → Customer Configuration → Name and Address Options → Show Telephone = Optional):

  1. Create an empty cart.
  2. Call setShippingAddressesOnCart without a telephone field:
mutation {
  setShippingAddressesOnCart(input: {
    cart_id: "CART_ID"
    shipping_addresses: [{
      address: {
        firstname: "John"
        lastname: "Doe"
        street: ["123 Main St"]
        city: "Austin"
        region: "TX"
        postcode: "78701"
        country_code: "US"
      }
    }]
  }) {
    cart { shipping_addresses { city } }
  }
}

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.

  1. Repeat with Show Telephone = Required — confirm a missing telephone is correctly rejected by server-side validation with a meaningful error.

Impact assessment

  • CartAddressInput is used by both setShippingAddressesOnCart and setBillingAddressOnCart. Both mutations benefit from this fix.
  • ValidateAddressFromSchema (used in output resolvers ShippingAddresses and BillingAddress) correctly treats telephone as optional since it now reads String from the schema — saved addresses without telephone are returned rather than silently nulled.
  • No other String! fields in CartAddressInput are affected.
  • The output type (CartAddressInterface.telephone: String) was already nullable and is unchanged.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit tests (ValidateAddressFromSchemaTest — 4 test cases covering nullable/NonNull field scenarios)
  • All automated tests passed successfully — CI pending

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
@m2-assistant

m2-assistant Bot commented Jul 29, 2026

Copy link
Copy Markdown

Hi @koushikch7. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.
❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

@koushikch7

Copy link
Copy Markdown
Author

@magento run all tests

@engcom-Bravo engcom-Bravo added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Jul 29, 2026
@github-project-automation github-project-automation Bot moved this to Pending Review in Pull Requests Dashboard Jul 29, 2026
@koushikch7

Copy link
Copy Markdown
Author

@magento run all tests

@koushikch7

Copy link
Copy Markdown
Author

@magento run Unit Tests

@koushikch7

Copy link
Copy Markdown
Author

WebAPI Tests Analysis

I'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.

Suite Passed Failed Notes
CE WebAPI GRAPHQL 1,831 0 Clean ✅
B2B WebAPI GRAPHQL 1 Pre-existing failure (newFailed: false)

The single B2B failure is:

"Order status should be 'received' after placing async order. Failed asserting that two strings are identical."

This is an async order status test in the B2B suite with newFailed: false — meaning it was already failing before this PR was opened. It has no connection to CartAddressInput.telephone.


Local Verification

I also verified the fix against a running Magento 2.4 instance:

Test Config Result
setShippingAddressesOnCart without telephone Telephone = Optional ✅ PASS — address set, telephone: null
setBillingAddressOnCart without telephone Telephone = Optional ✅ PASS — address set, telephone: null
setShippingAddressesOnCart without telephone Telephone = Required ✅ PASS — server-side validation correctly rejects: "telephone" is required. Enter and try again.
setShippingAddressesOnCart with telephone Telephone = Required ✅ PASS — address set with telephone value

Schema introspection confirms CartAddressInput.telephone is now String (nullable) while firstname, lastname, country_code remain String! (required).

The fix is minimal, correct, and backward-compatible. No existing tests are broken by this change.

@koushikch7

Copy link
Copy Markdown
Author

@magento run WebAPI Tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: pending review

Projects

Status: Pending Review

Development

Successfully merging this pull request may close these issues.

GraphQL: CartAddressInput.telephone is required in 2.4.9 even when Telephone is configured as Optional

2 participants