Empty fields are 'unexpected'

Describe your question/issue in detail

I have a situation where a content relationship field is apparently non-existent if it is not filled anywhere in the repository.

I have added an 'author' content relationship field to my blog_post page type. The target of this field is my 'profile' page type.

There are two purposes here. One is to show the author's photo and name on the blog post. The second is so I can filter blog posts by author.

For the second purpose I have added filters to my PageIndex slice, so the pages included in the index are determined by client.getAllByType('blog_post', blogOpts), where blogOpts contains the filters derived using filter.at('my.blog_post.author', filters.authorId).

Having added this function to my website, all the 'author' content relationship fields are empty. So I expect to see the 'no results found' message when filtering for an author. Instead, the slice crashes and I see this message in my logs:

Error: [function at(..)] unexpected field 'my.blog_post.author' on line:1 col:6 in query '[[at(my.blog_post.author, "anzmghEAACcA1gXh")]]'

This suggests to me that 'author' is undefined, despite it being part of the model for the page type.

I did some investigations of this issue by creating a profile page and linking to it from a blog post. This fixed the problem, including for filters that returned no results. When I removed the links to the profile and archived the profile page, the problem returned.

Hey @ben7,

Thanks for raising this. This is a known bug, we're tracking it on our side and I've added your report to the existing ticket for awareness and to let the team know this is still affecting users. As a workaround for now, you have two options:

1. ​Always publish at least one document with the field filled​ — this is the easiest fix, and might work out fine in your case (though beware it will break again if that doc gets archived/unpublished, as you found).
2. ​Catch the error / ParsingError and treat it as empty results​, or drop the predicate and filter client-side. This will ensure that when the bug happens, it doesn't crash, only handles the error.

Let me know if you need more help with this!