Incorrect collection productsCount (somehow negative)

When querying (with GraphQL) the products count of a collection, in rare instances we return a negative number - which is obviously incorrect and causes a large number of issues for us.

query checkAssets {
        collection(id: "gid://shopify/Collection/285327196259") {
            productsCount {
                count
                precision
            }
            updatedAt
            products(first: 250) {
                pageInfo {
                    hasNextPage
                    endCursor
                }
                edges {
                    node {
                        id
                        title
                    }
                }
            }
        }
    }

This negative productsCount is also on the /collections/collection-handle.json version of the collection frontend:

The collection I’ve referenced has over 1000 products.

What is going on here?

Hi - thanks for flagging this, connecting with the relevant product team on this.

@Liam-Shopify

Here is another case. Can you confirm that it’s an internal issue?

I query that way:

collection(id: $id) {
  title
  productsCount {
    count
    precision
  }
}

And I get: { title: 'test456', productsCount: { count: 26, precision: 'EXACT' } }

On the admin the same collection has 24 products:

I double checked that I used the right collection ID to query it.

Also note that after adding/removing products using the graphql api, the value is now correct

Hi - our devs have identified there is an issue on our side, and are working on a fix.