Duplicates in Vision but not in Desk

4 replies
Last updated: Jun 22, 2023
Hi! I need help urgently! I am getting duplicates in vision but not seeing duplicates in the desk section!
AI Update

This is a common issue! You're seeing duplicates in Vision but not in the Desk (Structure) tool because they handle document queries differently.

What's happening:

Vision queries your Content Lake directly and returns all documents that match your query, including both draft and published versions. The Desk tool, however, is smart about this - it automatically filters and merges these versions to show you just one entry (preferring the draft version when it exists).

In Sanity, when you edit a document, it creates a draft with an ID like drafts.your-doc-id while the published version keeps the ID your-doc-id. Vision sees these as two separate documents, but the Desk tool knows they're the same document in different states.

To diagnose the issue:

You can use this GROQ recipe to identify duplicates. Run this in Vision:

*[_type == $type] {
  "duplicates": *[_type == $type && @[$findDups] == ^[$findDups] && _id != ^._id && !(_id in path('drafts.**'))] {_id, $findDups: @[$findDups]}
}[count(duplicates) > 0]

// Params
{
  "type": "yourDocumentType",
  "findDups": "title"
}

Replace "yourDocumentType" with your actual document type and "title" with the field you want to check for duplicates.

To fix your Vision query:

If you want Vision to show results like the Desk tool, you can filter out drafts:

*[_type == "yourType" && !(_id in path("drafts.**"))]

Or use a newer API version (like v2021-03-25 or later) with the published perspective, which automatically handles this for you.

Is this actually a problem?

If you're only seeing drafts.doc-id and doc-id pairs, this is completely normal and not a problem - it's just how Sanity's draft/publish system works. If you're seeing true duplicates (multiple documents with the same content but different IDs), then you may need to clean up your data.

Show original thread
4 replies
desk only shows either a draft of published version. Vision shows one entry for each (draft and published)
I figured out how to hide the drafts!
user L
is there a way to filter out drafts globally when fetching in plasmic?
Sorry, I have no idea about that.

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?