Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot patch document data if document slug already exists #4016

Open
ansmlc opened this issue Dec 22, 2022 · 0 comments
Open

Cannot patch document data if document slug already exists #4016

ansmlc opened this issue Dec 22, 2022 · 0 comments

Comments

@ansmlc
Copy link

ansmlc commented Dec 22, 2022

In scenario where there's two documents with an identical slug field present in Sanity Studio, neither document can be patched via the HTTP mutations API, despite the documents having different IDs.

In my setup Sanity content is supposed be synced from a Shopify store using webhooks. The syncing works in all cases except in this case where there's two documents with same slug.

Example snippet from my API where I try force setting a new slug for the document in Sanity.

// api/shopify/product-update.js


 const slugField = {
    slug: {
      current: handle,
    }
  }

  // patch (update) slug, missing or not 
  stx = stx.patch(`product-${id}`, (patch) => patch.set(slugField))


When console-logging handle it in fact has the new, correct value as edited in Shopify.
I also tried to unset the field, but that didn't work either:


 // unset slug field

 const slugField = ["slug"];
 stx = stx.patch(`product-${id}`, (patch) => patch.unset(slugField))

As to why there are products with duplicate slug values, it's a result of switching to different Shopify store which had cloned all product data from previous store, so now there's duplicate products with duplicate slugs, neither of which can be deleted, and the new products can't be published either because of the duplicate slug validation error.

As to why the old duplicate documents aren't deleted, it's because of another bug where Sanity thinks there are existing references elsewhere in Studio referencing this document, even if all other referenced are deleted.

A clear and concise description of what the bug is.

To Reproduce

Steps to reproduce the behavior:

  1. Setup HULL with a Shopify store
  2. Switch Sanity Studio to fetch product data from a different Shopify store, which has identical, cloned content
  3. There's now duplicate product documents
  4. See "URL Slug already in use" error.
  5. Try to patch documents with new slug data

Expected behavior

I expect to be able to either patch or delete the document.

Screenshots
image

Which versions of Sanity are you using?

$ sanity versions
@sanity/cli 2.30.0 (latest: 3.1.2)
@sanity/base 2.30.0 (latest: 2.35.2)
@sanity/cli 2.30.0 (latest: 3.1.2)
@sanity/code-input 2.35.0 (latest: 3.0.1)
@sanity/color-input 2.30.0 (latest: 3.0.1)
@sanity/components 2.14.0 (up to date)
@sanity/core 2.30.0 (latest: 2.35.0)
@sanity/dashboard 2.30.1 (latest: 3.1.1)
@sanity/default-layout 2.30.0 (latest: 2.35.2)
@sanity/default-login 2.30.0 (latest: 2.35.2)
@sanity/desk-tool 2.30.0 (latest: 2.35.2)

Windows 10, MacOS

Which versions of Node.js / npm are you running?

8.19.2
v19.0.1

Additional context]

See:
ndimatteo/HULL#116
#1850

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant