Query parsing error when no documents with a Link field value

I have the following custom types (simplified for this post):

Blog Category (blog_category):

{
  "Main" : {
    "uid" : {
      "type" : "UID",
      "config" : {
        "label" : "Page Slug",
        "placeholder" : "Unique identifier for category URL"
      }
    },
    "title" : {
      "type" : "Text",
      "config" : {
        "label" : "title"
      }
    },
  },
}

Blog Subcategory (blog_subcategory):

{
  "Main" : {
    "uid" : {
      "type" : "UID",
      "config" : {
        "label" : "Page Slug",
        "placeholder" : "Unique identifier for subcategory URL"
      }
    },
    "title" : {
      "type" : "Text",
      "config" : {
        "label" : "title"
      }
    },
    "category" : {
      "type" : "Link",
      "config" : {
        "select" : "document",
        "customtypes" : [ "blog_category" ],
        "label" : "Category"
      }
    }
  }
}

I am fetching all blog_subcategory documents which have a category value using the following query:

const data = client.query(
  [
    Prismic.Predicates.at('document.type', 'blog_subcategory'),
    Prismic.Predicates.has('my.blog_subcategory.category'),
  ],
  opts
)

which results in this query string:

q=%5B%5Bat(document.type%2C+%22blog_subcategory%22)%5D%5Bhas(my.blog_subcategory.category)%5D%5D

If I have no blog_subcategory documents or no blog_subcategory documents with a category value set, I would expect the response from the request above to return 0 documents. Instead it returns a 400 response with the following error:

{
  "message": "[function has(..)] unexpected field 'my.blog_subcategory.category' on line:1 col:46 in query '[[at(document.type, \"blog_subcategory\")][has(my.blog_subcategory.category)]]'\n[[at(document.type, \"blog_subcategory\")][has(my.blog_subcategory.category)]]\n                                              ^\n","type":"parsing-error","line":1,"column":46,"id":0,"location":"query"
}

As soon as I add at least one blog_subcategory document which has a category value, the query returns the documents as expected.

I have also tested the above using the API Browser which results in the same behaviour.

Is the error response above expected behaviour?

Hi @patts. The 400 response you’ve seen is the expected behavior. As you’ve discovered, the way to fix it is to publish at least one document of that type.

I completely agree that it makes more sense for the API to return 0 responses, though. So I will let the @features-team know about this and we will add this to our feature request tracker as a possible improvement for the future. We don’t have any plans to work on this right now, but we will let you know here if that changes at any point.

This is being tracked as an open feature request.

If you have another use-case for this feature, you can 'Flag' this topic to reopen. Please use the :heart: button to show your support for the feature and check out our Feature Request Guidelines.