This document is of type ABC" error persists after upgrading to 2.21.9

5 replies
Last updated: Nov 29, 2025
I’m wrestling with the “This document is of type ABC and cannot be edited as XYZ” bug with singletons on one of my sites. I upgraded to 2.21.9 from 2.21.4, but the bug persists. I’ve tried restoring the affected documents to a previous version, but I am unable. I’ve looked through as many Slack threads and GitHub Issues that I can find, but most of them end like two weeks ago, which suggests to me that the fix worked for many people.
Is there something I need to do to get the fix to kick in? Is there a way around this other than deleting the documents?
AI Update

I feel your pain with this singleton bug! Unfortunately, based on the information from the Sanity team, if a document was created or updated during the period when that regression was active, upgrading to version 2.21.9 alone won't automatically fix it. The document itself has corrupted _type metadata that persists even after the Studio fix.

The bad news is that these affected documents do need to be deleted and recreated. The good news is there are a couple of approaches to minimize the pain:

Option 1: Export, Edit, and Re-import (Recommended)

This approach from Sanity's support team lets you preserve your content:

  1. Export your dataset: sanity dataset export <dataset> <filename>.tar.gz
  2. Untar the file: tar -xzf <filename>.tar.gz (Mac/Linux)
  3. Open <folder-that-was-untarred>/data.ndjson in your editor
  4. Find the problem document (one per line) and change the _type to the correct value. Copy the _id
  5. Delete the document: sanity documents delete <_id> (add --dataset=<dataset> if needed)
  6. Repeat steps 4-5 for each affected document
  7. Create a new tarball: tar -czf <new-filename>.tar.gz <folder-that-was-untarred>
  8. Import with: sanity dataset import <new-filename>.tar.gz <dataset> --replace

Important: Test this on a non-production dataset first if possible!

Option 2: Use the HTTP API

You can also copy the document's JSON and create a new document with the correct _type using the HTTP Mutations API before deleting the old one. This gives you more control but requires writing some code.

The core issue is that the _type field in the stored document doesn't match what the Studio expects for that singleton, and there's no automatic migration path. The fix in 2.21.9 prevents new documents from getting corrupted, but doesn't heal existing ones.

If you have multiple affected documents, scripting the export/edit/import process would definitely save time over doing it manually!

Show original thread
5 replies

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?