Product Option Value ID Changes when Variants Are Edited

We have an app that allows our users to “better group” customers based on what they purchase. More specifically things like “Red version of some shirt”. One thing the customers requested was the ability to keep tracking the same “item” when product and options are renamed. So, at most fine grained level, what we need to track are orders with a specific Option Value (mind you, not a variant because customers want Red shirts, not XL-Red shirts).

After implementing this logic, I was thrown off when I realized the ProductOptionValue Id completely changes when you edit the option value name. This was completely unexpected as an Id is supposed to be that one stronghold that people can rely on to uniquely identify things as the extrinsic properties change freely.

It seems very much inefficient to capture the product updates and then update the potentially tens of thousands of entries in our database for each option value as well as the customer segments and other side entities created through our system linked to this option.

Is there any way for me to track orders with a specific option value (i.e. Red) even when the product/value/variant names might change?

Would also welcome some insight on why this particular Id changes along with the name. Genuinely curious why this decision was made

02:23:29 │                     remix │ [
02:23:29 │                     remix │   {
02:23:29 │                     remix │     name: 'Date',
02:23:29 │                     remix │     optionValue: {
02:23:29 │                     remix │       id: 'gid://shopify/ProductOptionValue/5711658451218',
02:23:29 │                     remix │       name: 'HOB2'
02:23:29 │                     remix │     },
02:23:29 │                     remix │     value: 'HOB2'
02:23:29 │                     remix │   }
02:23:29 │                     remix │ ]

After changing HOB2 → HOB3

02:27:39 │                     remix │ [
02:27:39 │                     remix │   {
02:27:39 │                     remix │     name: 'Date',
02:27:39 │                     remix │     optionValue: {
02:27:39 │                     remix │       id: 'gid://shopify/ProductOptionValue/5711975612690',
02:27:39 │                     remix │       name: 'HOB3'
02:27:39 │                     remix │     },
02:27:39 │                     remix │     value: 'HOB3'
02:27:39 │                     remix │   }
02:27:39 │                     remix │ ]

The query that the data is extracted from (printing out selectedOptions

`#graphql
    query ($id: ID!){
        productVariant(id: $id) {
              id
              title
              displayName
              selectedOptions{
                 name
                 optionValue {
                     id
                     name
                  }
                  value
               }
               title
         }
     } 
`

Hey @Sinan_Pehlivanoglu,

Thanks for the post and the clarity on how the changing ID is making things difficult and inneficient.

I’m happy to dig in to this further with you. It would help to have a little more context on how the products are being updated (specific mutations and responses if possible). That will help me set up to see this on my own test store and see if there are any alternatives that will help keep the data you need (or at least how to access it when an option changes).

Thank you @KyleG-Shopify for your response and your offer for help. The option name is changed through the admin dashboard, our app doesn’t mutate any products.

The minimum steps to reproduce would be the following:

  1. Create a product with options (one option with two values would be sufficient). Name one of the option values “My Option v1”
  2. Fetch the product through the GraphQL API, make sure options { .. optionValues{id name} ..} is included in the response. Locate the Product Option Value ID for My Option v1 and make note of it
  3. Navigate to admin dashboard, click on the product you created, scroll down to the variants. Click on “My Option v1”, edit the name to “My Option v2”
  4. Once again fetch the product through the GraphQL API. Locate the option value ID for “My Option v2” and make note of it. You will notice the ids no longer match even though a new value wasn’t created, but an existing one was edited

I am including a screen recording of this for your convenience which you can access:

https://drive.google.com/file/d/1yh02QmmgIG11gFwKXq8lniEvzD5x6Hd8/view?usp=sharing

Thank you in advance for your help. Please let me know if there is any further information I can provide