Bug with singletons persists after upgrade, workaround involves deleting and recreating affected documents.

5 replies
Last updated: Nov 23, 2021
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?
Nov 4, 2021, 3:29 PM
Hi User. Unfortunately, it sounds like a document created or updated while we experienced that regression will need to be deleted and recreated. You may be able to save some time by copying the document’s JSON and copying it to a new document with the API before deleting it. If you want help with that, please let me know.
Nov 7, 2021, 2:19 PM
Bummer. Thanks for letting me know. I’m not in front of my computer, but as long as you’re here, I would be grateful for a few pointers.
Nov 7, 2021, 2:24 PM
I just tested this approach and it seemed to work. It might be an option. Best to test on a non-production dataset first, if possible.
1. Export your dataset.
sanity dataset export <dataset> <filename>.tar.gz
2. Untar the file.
tar -xzf <filename>.tar.gz
on Mac/Linux.3. Open
<folder-that-was-untarred>/data.ndjson
in your editor. 4. Locate the problem document (there’s one document per line) and change the
_type
to the one desired. Copy the
_id
.5. In the terminal, run
sanity documents delete <_id>
. Add the
--dataset=<dataset>
flag if you need to work with your non-default dataset.6. Repeats steps 4-5 for as many documents that need to be changed. If there are more than a few, it’s probably faster to script this.
7. Close the editor and create a tarball from the entire folder with
tar -czf <new-filename>.tar.gz <folder-that-was-untarred>
. Don’t overwrite the old tarball as we want to keep that until we have confirmed everything went well.8. Import the new tarball with
sanity dataset import <new-filename>.tar.gz <dataset> --replace
.The original approach—copying the JSON and using the API to set it into a new document with the correct `_type`—is also an option.
Nov 7, 2021, 2:44 PM
Hi
user A
. I was finally able to get this squared away. Thanks for your help and for your clear instructions.
Nov 23, 2021, 9:35 PM
That’s great! I’m glad to hear it. Thanks for letting me know.
Nov 23, 2021, 9:37 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?