Error importing documents with Sanity CLI, caused by invalid document ID
2 replies
Last updated: Feb 27, 2023
W
I posted some context in the thread above, but since this is not exactly the same issue as the OP of that thread I figured I should write up what we’re seeing as well.
I’m trying to use the CLI to import from a file. Earlier today I was successfully uploading with a
A few things that I’ve tried:
• Uninstalling and re-installing the CLI.
• Logging out and logging back in via the CLI (multiple times). Worth noting that I’m authenticating as an admin user on the account.
• Using both a
I’m at a bit of a loss for what else to try here. It seems this issue popped up out of nowhere, and I can’t find any references to the same problem online. Is anyone at Sanity able to offer some guidance here?
I’m trying to use the CLI to import from a file. Earlier today I was successfully uploading with a
.ndjsonfile, but coming back after a break I’m suddenly hitting the error below.
A few things that I’ve tried:
• Uninstalling and re-installing the CLI.
• Logging out and logging back in via the CLI (multiple times). Worth noting that I’m authenticating as an admin user on the account.
• Using both a
.ndjsonfile directly, and compressing the file into a
.tar.gzarchive.• Bisecting the file to reduce it’s size. I was able to successfully upload ~211 documents using this method, which makes me think that perhaps the size of our file might be the issue (roughly 2400 documents) We’re expecting to upload tens-hundreds of thousands of documents for this current migration task, so if this is a size issue Sanity becomes untenable for us.
I’m at a bit of a loss for what else to try here. It seems this issue popped up out of nowhere, and I can’t find any references to the same problem online. Is anyone at Sanity able to offer some guidance here?
✔ [100%] Fetching available datasets ✔ [100%] Reading/validating data file (178ms) ✖ [ 0%] Importing documents (2.17s) Error: Mutation(s) failed with 1 error(s) at onResponse (/Users/will/Library/Application Support/fnm/node-versions/v16.16.0/installation/lib/node_modules/@sanity/cli/lib/_chunks/loadEnv-75c46c66.js:1666:13) at applyMiddleware (/Users/will/Library/Application Support/fnm/node-versions/v16.16.0/installation/lib/node_modules/@sanity/cli/node_modules/get-it/dist/index.cjs:60:15) at onResponse (/Users/will/Library/Application Support/fnm/node-versions/v16.16.0/installation/lib/node_modules/@sanity/cli/node_modules/get-it/dist/index.cjs:133:22) at /Users/will/Library/Application Support/fnm/node-versions/v16.16.0/installation/lib/node_modules/@sanity/cli/node_modules/get-it/dist/index.cjs:115:55 at callback (/Users/will/Library/Application Support/fnm/node-versions/v16.16.0/installation/lib/node_modules/@sanity/cli/node_modules/get-it/dist/index.cjs:423:46) at /Users/will/Library/Application Support/fnm/node-versions/v16.16.0/installation/lib/node_modules/@sanity/cli/node_modules/get-it/dist/index.cjs:486:14 at DestroyableTransform.<anonymous> (/Users/will/Library/Application Support/fnm/node-versions/v16.16.0/installation/lib/node_modules/@sanity/cli/node_modules/get-it/dist/index.cjs:260:13) at Object.onceWrapper (node:events:641:28) at DestroyableTransform.emit (node:events:539:35) at endReadableNT (/Users/will/Library/Application Support/fnm/node-versions/v16.16.0/installation/lib/node_modules/@sanity/cli/node_modules/readable-stream/lib/_stream_readable.js:1010:12)
Feb 24, 2023, 12:49 AM
W
For anyone else running into this issue, the root cause was that there was a single document in our file that had an id that started with
I was able to figure this out by bisecting the data until I got to that record. Re-working our logic to only use alphanumeric characters for the id resolved the problem.
-(which is invalid).
I was able to figure this out by bisecting the data until I got to that record. Re-working our logic to only use alphanumeric characters for the id resolved the problem.
Feb 24, 2023, 4:39 PM
R
Thanks for sharing your solution!
Feb 27, 2023, 8:11 PM
Sanity– build remarkable experiences at scale
The Sanity Composable Content Cloud is the headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.