Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Troubleshooting a schema issue with reference fields in Slack thread

32 replies
Last updated: Sep 8, 2021
⚠️ Sanity Team, I'm in a really weird spot where my reference fields are failing with the following error message:
Reference search failed
Attribute name cannot be an empty string
Upon inspection, it looks like I'm running into a schema issue or something. This error only seems to appear with specific doc types. I've narrowed it down to specific doc types, but I can't tell where the error is stemming from.

It looks like my studio query is setting an attribute name to
@[""]
which can be seen in this XHR request in Chrome developer tools:
<https://x6q9abew.api.sanity.io/v2021-03-25/data/query/development?query=*[_type> in $__types&&!(_id in path('drafts.**'))][0...$__limit]{_type == "pageArchive" => { "w0": _id,"w1": _type,"w2": title,"w3": @[""],"w4": slug.current,"w5": message,"w6": seo.seoTitle,"w7": seo.seoDescription },}&$__types=["pageArchive"]&$__limit=1000&tag=sanity.studio.search.reference
Note:
"w3": @[""]

Of course, this is coming at a time when we're trying to launch a site.

Anyone able to shed some light on this?
Sep 7, 2021, 11:34 PM
What's the fastest way for me to check that?
Sep 7, 2021, 11:37 PM
user M
☝️
Sep 7, 2021, 11:37 PM
sanity versions
Sep 7, 2021, 11:38 PM
@sanity/cli                  2.1.4 (latest: 2.18.0)
@sanity/base                2.17.0 (latest: 2.18.0)
@sanity/cli                 2.17.0 (latest: 2.18.0)
@sanity/components          2.14.0 (up to date)
@sanity/core                2.17.0 (latest: 2.18.0)
@sanity/dashboard           2.17.0 (latest: 2.18.0)
@sanity/default-layout      2.17.0 (latest: 2.18.0)
@sanity/default-login       2.17.0 (latest: 2.18.0)
@sanity/desk-tool           2.17.0 (latest: 2.18.0)
@sanity/production-preview  2.15.0 (up to date)
@sanity/uuid                 3.0.1 (up to date)
@sanity/vision              2.15.0 (latest: 2.17.2)
Sep 7, 2021, 11:38 PM
user M
Should I be upgrading?
Sep 7, 2021, 11:39 PM
user M
Should I be upgrading?
Sep 7, 2021, 11:39 PM
Yep! Give it a shot! Also, you say you've narrowed down the particular doc types. Can you share the relevant code so I can try to replicate if upgrading doesn't work?
Sep 7, 2021, 11:41 PM
Yeah sure
Sep 7, 2021, 11:42 PM
Let me give upgrading a shot
Sep 7, 2021, 11:42 PM
user M
Looks like upgrading didn't help. This is my schema JSON for the doc above:
{
    "name": "pageArchive",
    "title": "Archive Page",
    "type": "document",
    "__experimental_actions": ["update", "publish"],
    "fieldsets": [
        {
            "name": "seo",
            "title": "SEO",
            "options": {
                "collapsible": true,
                "collapsed": true
            }
        },
        {
            "name": "meta",
            "title": "Meta",
            "options": {
                "collapsible": true,
                "collapsed": true
            }
        }
    ],
    "fields": [
        {
            "name": "title",
            "title": "Title",
            "validation": null,
            "type": "string"
        },
        {
            "name": "slug",
            "title": "Slug",
            "description": "Leave blank to autofill.",
            "options": {
                "source": "title",
                "maxLength": 96,
                "minLength": 4
            },
            "readOnly": true,
            "type": "slug",
            "fieldset": "meta"
        },
        {
            "name": "message",
            "title": "Message",
            "validation": null,
            "message": "This page is populated with Posts",
            "inputComponent": {
                "propTypes": {}
            },
            "type": "string"
        },
        {
            "name": "seo",
            "title": " ",
            "validation": null,
            "fieldset": "seo",
            "type": "seo"
        }
    ],
    "preview": {
        "select": {
            "title": "title",
            "media": "image",
            "subtitle": ""
        }
    }
}
Sep 7, 2021, 11:52 PM
The inputComponent for
message
is a component called
AdminMessage
that just displays a message in the admin.
Sep 7, 2021, 11:53 PM
What else can I provide that will be helpful?
Sep 7, 2021, 11:53 PM
Which field contains the failing reference? Sorry I'm not seeing it.
Sep 8, 2021, 12:00 AM
Oh sorry, that's the doc that is being referenced. Here's the doc that is throwing that error:
Sep 8, 2021, 12:03 AM
Well, it's actually just a reference field that references
pageArchive
.
Sep 8, 2021, 12:03 AM
Off the top of my head,
title
under
seo
is
" "
. Also, does it help to remove
subtitle
from your
select
, since it's set to
""
?
Sep 8, 2021, 12:04 AM
Holy crap.
Sep 8, 2021, 12:06 AM
Wow.
Sep 8, 2021, 12:06 AM
Holy crap.
Sep 8, 2021, 12:06 AM
SEO title was fine
Sep 8, 2021, 12:06 AM
But the
subtitle = ""
was breaking it.
Sep 8, 2021, 12:06 AM
WOW
Sep 8, 2021, 12:07 AM
I feel like an idiot.
Sep 8, 2021, 12:07 AM
Hahaha
Sep 8, 2021, 12:07 AM
There are no idiots here, haha!
Sep 8, 2021, 12:07 AM
Thanks for your help!
Sep 8, 2021, 12:07 AM
Happy to help!
Sep 8, 2021, 12:07 AM
We've built a tool that helps build out schema faster...
Sep 8, 2021, 12:07 AM
And... apparently that's one of the things that it also does.
Sep 8, 2021, 12:07 AM
Breaks studio ahaha.
Welp. Thank you soooo much.
Sep 8, 2021, 12:07 AM
Very glad we got it working again!
Sep 8, 2021, 12:08 AM
🙌 🙏
Sep 8, 2021, 12:08 AM

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?