"Any" predicate with a field path returns 400 error if that field is both in a tab and empty in all documents

I'm working on an article filter right now. Each article has a group field that contains a content relationship to the "Categories" custom type. I've set up the query to filter by Categories like so:

const newsArticles = await $prismic.api.query(
        $prismic.predicates.any('my.news_articles.categories.category', [

(Note: "document-id-here" is just a placeholder. I am testing this with real IDs)

If at least one of my news_articles documents has content in the "Categories" group field, the query works. However, if none of the news_articles documents have any content in the "Categories" group field, the query fails with the following error and breaks the site:

Unexpected status code [400] on URL https://example.cdn.prismic.io/api/v2/documents...

In the Network tab, the error reads:

[function any(..)] unexpected field 'my.news_articles.categories.category' on line:1 col:7 in query '[[any(my.news_articles.categories.category, ["document-id-here"])]]'\n[[any(my.news_articles.categories.category, ["document-id-here"])]]\n ^\n

After doing some digging, I found this issue only occurred if the empty field was in a tab other than Main. I was able to reproduce the error with multiple field types ONLY if they were in a different tab than Main. Prismic handled the same empty field types in the Main tab without error.

Hi Laura,

Welcome to the community!

This is the normal behaviour for the API to return 400 errors in this case when there are no linked documents. I agree this could be improved and show no response instead.

The strange thing is that you should see this behaviour regardless of the tab, because the tabs are only for organisation and don't effect the API response.


Okay, good to know that's normal. Just wanted to make sure I wasn't missing something. Thank you!

1 Like