collectionReorderProducts Job working 50% of the time

InGraphQL last version, we are seeing “collectionReorderProducts“ work about 50% of the time.
Once the Job is marked as Done by Shopify the position of the product in the collection is simply not changed (even waiting for 2 hours), nor any error is returned.

Sending the EXACT same query a second time usually works but that is not an acceptable behavior for a GraphQL mutation.

Can someone at Shopify look into this?

Mutation + Variables example

mutation CollectionReorder($id: ID!, $moves: [MoveInput!]!) {
  collectionReorderProducts(id: $id, moves: $moves) {
    job {
      id
      done
    }
    userErrors {
      field
      message
    }
  }
}

Variables

{
    "id": "gid://shopify/Collection/321086259371",
    "moves": [
        {
            "id": "gid://shopify/Product/7265694515371",
            "newPosition": "2"
        },
        {
            "id": "gid://shopify/Product/8267387732139",
            "newPosition": "6"
        },
        {
            "id": "gid://shopify/Product/7265693630635",
            "newPosition": "0"
        },
        {
            "id": "gid://shopify/Product/7265693401259",
            "newPosition": "3"
        },
        {
            "id": "gid://shopify/Product/8459654725803",
            "newPosition": "1"
        }
    ]
}
3 Likes

Hey @BluedgeUSA,

When the job returns done: true but positions don’t update, are you checking the collection via API queries, the Admin, or the storefront?

The reason I ask is this will help determine if we’re dealing with a caching issue or if the job is completing without actually processing the reorder.

For one of the mutations that failed to reorder correctly, can you share:

  • The x-request-id from the response headers
  • The job.id that was returned

I would also recommend reviewing this thread as it also has some suggestions for making these queries more efficient.

Hi @KyleG-Shopify

I could not replicate that issue a couple days and I finally could with this Job Id: gid://shopify/Job/6dfdc9b0-61e8-4f56-8e2c-2bbe9b298836

Note: We are checked the order with the Admin backend, and graphQL.

The issue is “Easy“ to replicate once you understand what was happening.

Basically, if a product is no longer part of a Smart Collection (Ie: the price change, a tag was removed, product was deleted…) and in the meantime you send this product number in the payload to be moved to a certain position, the Job will not officially fail, bit the other products will not be reordered either.

This create a situation impossible to handle properly.

Given Jobs are asynchronous, I would suggest the system should still proceed with the other products that need reordering.

Hey @BluedgeUSA, I tried replicating the issue you’re experiencing and got different results than what you’re seeing:

  1. Created a smart collection with tag-based rules
  2. Removed the tag from a product (making it ineligible)
  3. Immediately sent a collectionReorderProducts mutation including that removed product in the moves array

The mutation completed successfully and correctly repositioned the valid products while ignoring the removed one. No silent failures.

Based on your “50% of the time” observation and the fact that running the same mutation twice typically works, this looks like a possible race condition between the smart collection recalculation job and your reorder mutation.

Would you be able to share a few more details in case I’m missing something in my test.

  • What triggers the product to leave the collection? (price change, tag removal, inventory change, etc.)
  • How quickly after the product change do you submit the reorder mutation?
  • Do you validate the product is still in the collection before attempting to reorder?

Hey @BluedgeUSA Are you still experiencing this issue, or can I mark this as solved?

Hi @KyleG-Shopify

We are running a number of test today and tomorrow. I will let you know what we find.

Thank you for keeping an eye on this.