Skip to content

Cannot return null for non-nullable field \"AppliedCoupon.code\" unexpected issue #39841

Open
@Dnd-Mafer

Description

@Dnd-Mafer

Preconditions and environment

Magento 2.4.8

Steps to reproduce

  • Create a salesrule with a specific coupon code available for everyone with a discount amount
  • Create a quote
  • Apply this coupon
  • Place the order
  • Get the order using GraphQL with the "applied_coupons.code" node
query getOrderByNumber($orderNumber: String!) {
  customer {
    orders(filter: { number: { eq: $orderNumber } }) {
      items {
        orderNumber: number
        applied_coupons {
          code
        }
      }
    }
  }
}

Expected result

{
  "data": {
    "customer": {
      "orders": {
        "items": [
          {
            "orderNumber": "000000003",
            "applied_coupons": [
              {
                "code": "h20"
              }
            ]
          }
        ]
      }
    }
  }
}

Actual result

{
  "errors": [
    {
      "message": "Internal server error",
      "locations": [
        {
          "line": 7,
          "column": 11
        }
      ],
      "path": [
        "customer",
        "orders",
        "items",
        0,
        "applied_coupons",
        0,
        "code"
      ],
      "extensions": {
        "debugMessage": "Cannot return null for non-nullable field \"AppliedCoupon.code\"."
      }
    }
  ],
  "data": {
    "customer": {
      "orders": {
        "items": [
          {
            "orderNumber": "000000003",
            "applied_coupons": [
              null
            ]
          }
        ]
      }
    }
  }
}

Additional information

Because of \Magento\SalesGraphQl\Model\Formatter\Order::format()

'applied_coupons' => $orderModel->getCouponCode() ? ['code' => $orderModel->getCouponCode()] : []

This should be encapsulate in an array

'applied_coupons' => $orderModel->getCouponCode() ? [['code' => $orderModel->getCouponCode()]] : [],

Release note

GraphQL - fix issue while getting applied_coupons.code on order

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Assignees

Labels

Area: OrderComponent: GraphQLGraphQLIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: ready for groomingReported on 2.4.8Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branch

Type

No type

Projects

Status

Ready for Development

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions