This document is of type ABC" error persists after upgrading to 2.21.9
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:
- Export your dataset:
sanity dataset export <dataset> <filename>.tar.gz - Untar the file:
tar -xzf <filename>.tar.gz(Mac/Linux) - Open
<folder-that-was-untarred>/data.ndjsonin your editor - Find the problem document (one per line) and change the
_typeto the correct value. Copy the_id - Delete the document:
sanity documents delete <_id>(add--dataset=<dataset>if needed) - Repeat steps 4-5 for each affected document
- Create a new tarball:
tar -czf <new-filename>.tar.gz <folder-that-was-untarred> - 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 thread5 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.