👀 Our most exciting product launch yet 🚀 Join us May 8th for Sanity Connect

Draft document deleted via CLI still showing in desk tool's main document list

10 replies
Last updated: Jun 16, 2023
I have a draft document that was created via the Sanity client like this:
transaction
    .createIfNotExists(document)
    .patch(draftId, patch => patch.set(document));
It was then deleted via the CLI but is still showing up in the desk tool's main document list for the doc type. The CLI and Vision both confirm the document does not exist, yet is still showing. This is happening on
v2.34
. Any ideas on how to resolve this?
Jun 16, 2023, 5:33 PM
Hi
user A
. It’s possible that the draft (with an
_id
of
drafts.document
) still exists.
Jun 16, 2023, 5:40 PM
Thanks for the reply
user A
. How can I delete it? Also why is the document with
drafts.
path showing in the main list, and in the browser URL? I haven't seen that behaviour before.
Jun 16, 2023, 5:42 PM
Actually, I missed your mention of it being a draft in your initial post. I’m not entirely sure I’m following your process. Please let me know if I have this right:
1. You created a draft document in the client that had an
_id
of
drafts.451f5de0-b1fc-4a2d-a92d-f58f9f84c160
.2. You opened that document in the Studio, and the
drafts.
prefix was in the URL.3. You deleted the document via the CLI with the command
sanity documents delete "drafts.451f5de0-b1fc-4a2d-a92d-f58f9f84c160"
.4. The document remains in the Studio’s document list, even though
drafts.451f5de0-b1fc-4a2d-a92d-f58f9f84c160
returns no results in Vision nor the CLI.If you open the document in the Studio and inspect the JSON, what’s the
_id
?
Jun 16, 2023, 5:50 PM
yes that process is correct. for one document, the URL shows the drafts path, but inspecting the JSON shows the published _id:
Jun 16, 2023, 5:55 PM
For the other document, the URL shows the drafts path, but the JSON shows no _id field at all. there is also no title field, even though the title is showing in the document list.
Jun 16, 2023, 5:56 PM
What shows in the URL bar for the other document?
Jun 16, 2023, 6:01 PM
URL:
drafts.c8a12195-35c7-4217-9475-33bb697fa73a
Jun 16, 2023, 6:02 PM
JSON:
Jun 16, 2023, 6:02 PM
user A
I think I figured out what was happening. The ID being used to patch the draft document could either be the published document's ID, or the draft ID. In the case where it was the draft ID, a new document with the ID of
drafts.drafts.c8a12195-35c7-4217-9475-33bb697fa73a
was actually created. This is why it was showing in the main list - what's weird is that the JSON inspect didn't show that as the ID. I was able to use the CLI to delete that double
drafts
version of the document, and update the transaction code so that doesn't happen now.
Jun 16, 2023, 9:53 PM
Wild! I’ve never come across that happening before, but I guess
drafts.drafts.ID
still fits the Studio’s expectation of a draft
_id
. Thanks for updating to let me know, and I’m glad you got it worked out!
Jun 16, 2023, 9:55 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?