magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

GraphQl customer orders query failed if try to retreive order item with deleted product

Open zakdma opened this issue 7 months ago • 18 comments

Preconditions and environment

  • Magento version 2.4.7-p1 (latest)

Steps to reproduce

  1. Install vanilla Magento instance
  2. Go to admin and create new simple product with SKU: simple-deleted
  3. Fill in all necessary product data to display it on front (stock, price, category etc.) and save it
  4. Reindex all
  5. Go to front and create new customer
  6. Find and add simple-deleted product to cart
  7. Go to checkout and place an order using some address data and default shipping and billing methods
  8. Go to admin and see the order is in Sales/Orders grid
  9. Open any GraphQl client and generate token using generateCustomerToken GraphQl mutation using previously created customer credentials https://developer.adobe.com/commerce/webapi/graphql/schema/customer/mutations/generate-token/
  10. Use the generated token in the following requests by adding it to Authorization header according to Magento GraphQl documentation
  11. perform query
query {
  customer {
    orders(currentPage: 1, pageSize: 999) {
      items {
        number
        items {
          product {
            sku
            name
          }
        }
      }
    }
  }
}
  1. See the correct response like this
{
  "data": {
    "customer": {
      "orders": {
        "items": [
          {
            "number": "000000001",
            "items": [
              {
                "product": {
                  "sku": "simple-deleted",
                  "name": "simple-deleted"
                }
              }
            ]
          }
        ]
      }
    }
  }
}
  1. Go to admin and delete product simple-deleted
  2. Perform the query again
query {
  customer {
    orders(currentPage: 1, pageSize: 999) {
      items {
        number
        items {
          product {
            sku
            name
          }
        }
      }
    }
  }
}

Expected result

There is a correct response with the data requested without any error

Actual result

There is error response like this

{
  "errors": [
    {
      "message": "Internal server error",
      "locations": [
        {
          "line": 7,
          "column": 11
        }
      ],
      "path": [
        "customer",
        "orders",
        "items",
        0,
        "items",
        0,
        "product"
      ]
    }
  ],
  "data": {
    "customer": {
      "orders": {
        "items": [
          {
            "number": "000000001",
            "items": [
              {
                "product": null
              }
            ]
          }
        ]
      }
    }
  }
}

Additional information

Check exception.log and see error like this

[2024-07-03T15:09:43.938496+00:00] main.ERROR: Missing key "associatedProduct" in Order Item value data

GraphQL (40:11)
39:           }
40:           product {
              ^
41:             id
 {"exception":"[object] (GraphQL\\Error\\Error(code: 0): Missing key \"associatedProduct\" in Order Item value data at /var/www/app/vendor/webonyx/graphql-php/src/Error/Error.php:155)
[previous exception] [object] (Magento\\Framework\\Exception\\LocalizedException(code: 0): Missing key \"associatedProduct\" in Order Item value data at /var/www/app/vendor/magento/module-sales-graph-ql/Model/Resolver/ProductResolver.php:46)"} []

Release note

No response

Triage and priority

  • [ ] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • [X] 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”.

zakdma avatar Jul 03 '24 15:07 zakdma