Solved

Metafields do not delete (via REST or GraphQL deletion) even though response confirms deletion.

patrickb
Shopify Expert
46 0 11

I have a toggle-able element on product pages that enables or disables depending on if a metafield exists or not.

95% of the time, when I delete the metafield via REST (and/or GraphQL) - this works perfectly fine. The metafield is now deleted, and my product page element no longer displays.

Occasionally - maybe once per 100 deletions. I receive a 200 success code back from Shopify for the metafield deletion, but when I actually go and check the Shopify product metafields minutes later, the metafield still exists.

My first thought was, okay, I will try to check for the metafield 30 seconds after I 'delete' it; and if it still exists then, I will try to re-delete it.

Unfortunately, this check (get all metafields for product via GraphQL) responds with my metafield still not existing.

So, current process is as follows - I thought this was foolproof to work, but merchants are still having issues.

1. Create metafield, record metafield ID in my database.

2. Delete metafield via metafield ID, receive success response from Shopify.

3. I also do a double deletion, where I try to loop over metafields on the product with my specific namespace, and delete any metafields that still exist.

4. 30 seconds after deletion, I check all product metafields for one that exists with my namespace. If it finds one, it tries to delete it again. Issue here = no matter what, in the past 4 weeks of running, this function never finds a metafield with my namespace. It is a GraphQL query and it returns all the other product metafields, but I don't see one with my namespace.

5. At this point, I log into the merchant Shopify store. Use a metafield app to confirm that the metafield still does exist, despite my rigorous attempts to delete it.

---

Again, this works most of the time, but once in a while it doesn't.

I have been struggling with this for over 1 year now. I have brought on other developers to help, I have asked in the Shopify Partner slack channel, and I still can not figure it out.

Can someone from Shopify perhaps help me out here?

I can provide exact timestamps, product IDs, and metafield IDs of where this happened. I can also show full server logs from my application to show you how I check for the metafield after deletion and don't see it there.

 

Recipe Kit - Easy, beautiful & SEO friendly recipe cards on your Shopify blog posts - https://apps.shopify.com/recipe-kit
Wait.li - Product Waiting Lists for Shopify - https://apps.shopify.com/product-waiting-lists
Accepted Solution (1)
mattrose
Shopify Staff (Retired)
12 4 6

This is an accepted solution.

Hey, I looked up what events occurred on the 20th. These ones stood out:

  1. At 1:12:27 PM UTC, the metafield with id `18894676918326` was deleted
  2. At 1:15:50 PM UTC (~3 minutes later), a new metafield with the same key was created by your Product Waiting Lists app
  3. At 3:19:22 PM UTC (~2 hours later) that metafield was destroyed (metafield id was `18967069130806`)

This was all done via the REST API.

Does this align with what you expect your app to do? I'm curious about the second event listed. Is it possible that your app is unintentionally creating a metafield with the same namespace and key a few minutes after it's deleted?

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Replies 10 (10)

mattrose
Shopify Staff (Retired)
12 4 6
when I actually go and check the Shopify product metafields minutes later, the metafield still exists

 When you still see the metafield exists, are you seeing this via the app you're using; or are you still able to query for the metafield via API after you've deleted? If it's the former, it could just be that the app has a stale cache of the metafields existence.

To learn more visit the Shopify Help Center or the Community Blog.

patrickb
Shopify Expert
46 0 11

Hey! Thanks for the response, Matt.

 

Basically the gist is:

- Checking for the metafield 30 seconds after supposed confirmed deletion via API call (GraphQL) show's no metafield existing. I haven't increased this delayed check time yet, as it could get confusing for a customer who may disable and then re-enable the widget.

- Checking by logging into the online store, seeing the widget still active on the store, and then checking the metafield by either using Shopify's hidden bulk metafield editor (or another third party app, not mine) shows that it still exists.

 

Let me know if that makes sense!

Thanks so much.

 

Recipe Kit - Easy, beautiful & SEO friendly recipe cards on your Shopify blog posts - https://apps.shopify.com/recipe-kit
Wait.li - Product Waiting Lists for Shopify - https://apps.shopify.com/product-waiting-lists
mattrose
Shopify Staff (Retired)
12 4 6

Checking for the metafield 30 seconds after supposed confirmed deletion via API call (GraphQL) show's no metafield existing

So it sounds like the API response is behaving as expected

seeing the widget still active on the store

This is likely due to the online store cache. I can look into this for you

using Shopify's hidden bulk metafield editor [...] shows that it still exists

Can you link me to the route you're using to see this. You also mentioned that you have timestamps, product IDs, and metafield IDs. Can you share an example if you have those on hand (no need to share server logs). Thanks 🙂

To learn more visit the Shopify Help Center or the Community Blog.

mattrose
Shopify Staff (Retired)
12 4 6

Looked into how metafields affect the online store cache—changes to metafields bust the cache, so changes to metafields should propagate relatively quickly on store front 🤔.

I can look into it more if you send those IDs and timestamps.

To learn more visit the Shopify Help Center or the Community Blog.

patrickb
Shopify Expert
46 0 11

Absolutely! I'm using the following URL scheme from this link: https://www.shopify.com/partners/blog/110057030-using-metafields-in-your-shopify-theme

https://shopify.com/admin/bulk?resource_name=Product&edit=metafields.global.isbn:string

Alternatively, I'm also using a Firefox extension (Poshify Utilities) for checking metafields. Both show that the metafield still exists.

For reference, I've now deleted the metafield with the ID that I will post the details of below; this was on a live client's store so I manually removed the metafield via the above link scheme so that the widget was disabled properly.

namespace: wait_li

Metafield ID: 18967069130806

Product ID: 4662201450550

I have these two fields from the metafield as well, of created_at and updated_at:
created_at: '2021-04-20T08:16:37-05:00',
updated_at: '2021-04-21T10:14:21-05:00',

The timestamp of deletion would have occurred at:

Apr 21 08:19:23 (Pacific Time - GMT - 08:00)

Checking for the metafield 25 seconds later at:
Apr 21 08:19:49 returned via GraphQL call that the metafield did not exist.

 

Received email from merchant probably 10 minutes later. Logged into store, checked via URL scheme above and saw that the metafield still existed.

 

Let me know if that is enough info; thank you so much for your help, Matt! Really appreciate this.

Recipe Kit - Easy, beautiful & SEO friendly recipe cards on your Shopify blog posts - https://apps.shopify.com/recipe-kit
Wait.li - Product Waiting Lists for Shopify - https://apps.shopify.com/product-waiting-lists
mattrose
Shopify Staff (Retired)
12 4 6

> I manually removed the metafield via the above link scheme so that the widget was disabled properly

I checked our logs, and it shows that the bulk editor wasn't used on April 21st by that shop—did you delete the metafield via the extension? I also didn't notice any UI in the bulk editor that allows you to delete metafields. My suspicion is that the app or extension you're using is either not successfully deleting the metafield, or that something is re-persisting the metafield after it's been deleted via a new upsert mutation.

To learn more visit the Shopify Help Center or the Community Blog.

patrickb
Shopify Expert
46 0 11

Hey Matt. Once again, can't thank you enough for looking into this.

I made a mistake in my last response; after chatting with my team member, this particular case was resolved (and have done this in the past) by re-creating a new metafield with the same namespace/key for the product, and then re-deleting it via the function in my app. Basically toggling enable/disable (create/delete) in my app. Somehow this second create/delete flushes out the metafield properly.

It makes sense that this is something wrong on my app's code side (by no means am I a fantastic coder, I trust your code more than mine!) - but the odd thing is that this happens so infrequently, and most customers never have an issue with (but is a big problem when it does happen).

Are you able to see the metafield ID being deleted on April 21st?

Let me know! Thanks so much, Matt!

 

Recipe Kit - Easy, beautiful & SEO friendly recipe cards on your Shopify blog posts - https://apps.shopify.com/recipe-kit
Wait.li - Product Waiting Lists for Shopify - https://apps.shopify.com/product-waiting-lists
mattrose
Shopify Staff (Retired)
12 4 6

This is an accepted solution.

Hey, I looked up what events occurred on the 20th. These ones stood out:

  1. At 1:12:27 PM UTC, the metafield with id `18894676918326` was deleted
  2. At 1:15:50 PM UTC (~3 minutes later), a new metafield with the same key was created by your Product Waiting Lists app
  3. At 3:19:22 PM UTC (~2 hours later) that metafield was destroyed (metafield id was `18967069130806`)

This was all done via the REST API.

Does this align with what you expect your app to do? I'm curious about the second event listed. Is it possible that your app is unintentionally creating a metafield with the same namespace and key a few minutes after it's deleted?

To learn more visit the Shopify Help Center or the Community Blog.

patrickb
Shopify Expert
46 0 11

Hey Matt.


Thanks so much for these event logs. That helps so much to help me dial this down.

I have a feeling you may have been my saviour here. I've got to look into some job queues I have setup - as I don't see a manual enabling event happening at 1:15:50 PM UTC on the 20th; but I do see another job running that does update the metafield.

You are a rockstar. I will get back to you ASAP if this solves it.

 

Recipe Kit - Easy, beautiful & SEO friendly recipe cards on your Shopify blog posts - https://apps.shopify.com/recipe-kit
Wait.li - Product Waiting Lists for Shopify - https://apps.shopify.com/product-waiting-lists
patrickb
Shopify Expert
46 0 11

You got it, Matt!

I had a delayed job running minutes after a merchant action was performed. This was calling to update the product metafield - which I thought would always exist. Updating it via REST API when the metafield doesn't exist causes the API to create a new metafield.


You are an absolute lifesaver. I truly can't thank you enough. Appreciate you so much, and appreciate you taking time out of your day to help me.

You rock!!

Recipe Kit - Easy, beautiful & SEO friendly recipe cards on your Shopify blog posts - https://apps.shopify.com/recipe-kit
Wait.li - Product Waiting Lists for Shopify - https://apps.shopify.com/product-waiting-lists