changeFromQuantity giving weird error

Weird in that I can’t figure out what’s actually wrong.

Here’s the current inventory status:

{"log":{"data":{"inventoryItem":{"id":"gid://shopify/InventoryItem/48756460355841","inventoryLevel":{"id":"gid://shopify/InventoryLevel/104683962625?inventory_item_id=48756460355841","quantities":[{"name":"available","quantity":1},{"name":"reserved","quantity":0}]}}},"extensions":{"cost":{"requestedQueryCost":3,"actualQueryCost":3,"throttleStatus":{"maximumAvailable":4000.0,"currentlyAvailable":3997,"restoreRate":200.0}}}}}

So, available = 1, reserved = 0. Matches gui.


mutation {
  inventoryMoveQuantities(
    input: {
      reason: "movement_created"
      referenceDocumentUri: "gid://shopify/Order/6918637519105"
      changes: [
        {
          inventoryItemId: "gid://shopify/InventoryItem/48756460355841"
          quantity: 1
          from: {
            locationId: "gid://shopify/Location/68409327873"
            name: "available"
            changeFromQuantity: 1
          }
          to: {
            locationId: "gid://shopify/Location/68409327873"
            name: "reserved"
            ledgerDocumentUri: "gid://mechanic/EventRun/0db90f82-2df5-439f-a964-2346147f680d"
            changeFromQuantity: 0
          }
        }
      ]
    }
  ) {
    inventoryAdjustmentGroup {
      reason
      changes {
        name
        delta
        item {
          id
          sku
        }
        location {
          name
        }
      }
    }
    userErrors {
      code
      field
      message
    }
  }
}





Moving 1 from available to reserved, passing qtys as above. This exact code works for other skus, but this one’s giving this error….

`GraphQL operation returned userErrors:

{
“inventoryMoveQuantities”: {
“inventoryAdjustmentGroup”: null,
“userErrors”: [
{
“code”: “CHANGE_FROM_QUANTITY_STALE”,
“field”: [
“input”,
“changes”,
“0”,
“to”,
“changeFromQuantity”
],
“message”: “The changeFromQuantity argument no longer matches the persisted quantity.”
}
]
}
}`

As if reserved’s changeFromQuantity is incorrect? Like how? Any ideas what’s going on?

EDIT: Might be because reserve qty had never been used before. Using changeFromQuantity: null worked, and then future edits with the actual qty number work fine. What gives?

Hey @pepsi_max2k :waving_hand: I had a look and your instinct in the edit is correct. Reserved has never been used for that item, so internally there’s nothing stored for it. The query shows 0, but the CAS check treats “never set” differently from “set to zero.” That’s why changeFromQuantity: 0 fails.

Passing null works because it skips the CAS check entirely. After that first move goes through, reserved gets initialized and integer values work going forward.

For your Mechanic task, you could either catch CHANGE_FROM_QUANTITY_STALE and retry with null, or just always pass null for the to side and only use CAS on the from side. I’m raising this with the relevant team since the query shouldn’t return 0 if CAS won’t accept 0.

Thanks - will stick with null for now.

Shame there’s no query to check if it is currently null - means always having to pass null, defeating the purpose of CAS :stuck_out_tongue: (I can’t try/catch in liquid). Hopefully someone implements something useful (just return null if it’s null??)