Cart/add.js, using FormData, never returns 422 out of stock response

Short description of issue

cart/add.js, using FormData, never returns 422 out of stock response

Reproduction steps

Following the FormData constructor approach in the Ajax Cart API docs here Cart API reference works, and allows products to be added to cart.

However, I’ve found on multiple stores, that the following steps result in a product being added to cart, instead of a 422 response being returned:

  1. Create a product with stock of 1, continue_selling_when_out_of_stock: false.
  2. Try adding two to cart

Result: items are added to cart.
If you then go to checkout, one is removed, as theres only 1 in stock.

Following the “items” appraoch above Cart API reference on the same stores, with the same products and the same form (just extracting the content out of FormData) results in the 422 response returning correctly in the above steps.

Additional info

Has anyone else experienced this, and have any suggestions?

I’ve found Shopify documentation of APIs etc to be excellent of recent years – but find the Ajax Cart API to be the one exception to that.

What type of topic is this

Bug report

This bug appear, if you add a product to the cart without “items” array. Just like an object:

{
id: variant_id,
quantity: 1
}

I noticed this recently. It looks like a Shopify bug, as it used to work fine without passing a single product in the items array.