Go Behind the Experience to see how Tecovas brings the West to life with Sanity 🤠 July 18th

Issue with "Unsupported path segment {}" error when viewing or editing card documents in Sanity Studio.

9 replies
Last updated: Jun 28, 2023
I am experiencing an issue in Sanity Studio where I am getting an "Unsupported path segment {} " error when trying to view or edit documents of type card. I have a card schema where there is a codes field which is an array of references to code documents.Here's the card schema for your reference:

export default {
  name: 'card',
  title: 'Card',
  type: 'document',
  fields: [
      name: 'title',
      title: 'Title',
      type: 'string',
      name: 'image',
      title: 'Image',
      type: 'image',
      name: 'rarity',
      title: 'Rarity',
      type: 'reference',
      to: [{type: 'rarity'}],
      name: 'series',
      title: 'Series',
      type: 'reference',
      to: [{type: 'series'}],
      name: 'totalCards',
      title: 'Total Cards',
      type: 'number',
      name: 'codes',
      title: 'Codes',
      type: 'array',
      of: [{type: 'reference', to: [{type: 'code'}]}]

The new codes are correctly added to the codes array of the card documents and there doesn't seem to be any orphaned reference. I'm getting the error after executing a script that creates code documents and then adds a reference to them in the codes array of card documents.

Do you have any insight into what could be causing this error and how it could be resolved?
Jun 28, 2023, 6:57 PM
We’ve seen this error before when an object gets added to an array without a
. In your script, are you either manually creating and adding keys or using autoGenerateArrayKeys: true ?
Jun 28, 2023, 7:02 PM
It appears I was not adding the key at all in the script.
Jun 28, 2023, 7:21 PM
I believe doing so should eliminate this error. Let us know how it goes!
Jun 28, 2023, 7:29 PM
Will do thank you for pointing me in the right direction i will update with my results.
Jun 28, 2023, 7:33 PM
One question. I just need to use autoGenerateArrayKey and this should fix the issue right?
Jun 28, 2023, 7:35 PM
Setting this to true should fix the error.
Jun 28, 2023, 7:35 PM
And also I am going to have to delete the records that are throwing this error as well?
Jun 28, 2023, 7:36 PM
That should work going forward. For the existing records, your approach will depend on how many exist. If it’s not too many, you could add keys manually. Just make sure they’re unique within their array.
Jun 28, 2023, 8:14 PM
user A
Great thank you for your help this resolved my issue.
Jun 28, 2023, 10:23 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?