Bug with projection/join of a reference inside an array in Sanity.io
12 replies
Last updated: Apr 26, 2021
Updating to
(the following is nested a few layers inside a query)
This returns what I expect, an array of objects with 3 keys each, with
This returns two arrays as expected, with
What’s happening here?
2021-03-25and having some trouble with projection/join of a reference inside an array.
(the following is nested a few layers inside a query)
'terpenes': terpenes[]{ percent, mg, 'name': terpene->name }
namebeing the proper name of the
terpenedoc.
'terpenes': terpenes[]{ percent, mg, 'name': terpene->name }, 'dominantTerpenes': terpenes|order(percent desc)[0..2]{ percent, mg },
dominantTerpenesonly returning the 3 with the highest
percent, however when I want the name in that array:
'terpenes': terpenes[]{ percent, mg, 'name': terpene->name }, 'dominantTerpenes': terpenes|order(percent desc)[0..2]{ percent, mg, 'name': terpene->name },
terpenesis still right but now
dominantTerpenesis an empty array 🤔
What’s happening here?
Apr 20, 2021, 2:34 PM
D
dig up this breaking change in the docs, wonder if it’s relevant in your case?
order() only works on arrays, and returns null otherwise
https://www.sanity.io/changelog?platforms=GROQ#5df909ebba61
order() only works on arrays, and returns null otherwise
https://www.sanity.io/changelog?platforms=GROQ#5df909ebba61
Apr 20, 2021, 2:46 PM
D
ah but it still returns an empty array so maybe not
Apr 20, 2021, 2:46 PM
A
That looks like a bug. I’ll see if we can reproduce it.
Apr 21, 2021, 1:50 PM
A
I’m not able to reproduce with
2021-03-25. Are you absolutely sure that this is the API version you’re testing?
Apr 21, 2021, 1:57 PM
A
It would also be helpful to see an example of a document you’re querying
Apr 21, 2021, 1:58 PM
A
I can reproduce it, and it looks like a very rare bug indeed. We’ll triage and hopefully get you a fix very soon.
Apr 21, 2021, 2:58 PM
M
I've been able to reduce it even further into this test: https://github.com/sanity-io/groq-test-suite/pull/47 .
The bug is related to an optimization pass not taking into account
The bug is related to an optimization pass not taking into account
order()in this situation. I've been able to fix it locally by disabling the optimization in this case, but I'll also try to see if I can make it work with both order and optimization because we want things to be fast as well!
Apr 22, 2021, 8:16 AM
M
Alright, I have a fix ready that will be rolled out soon!
Apr 26, 2021, 7:41 AM
M
And it's now fully rolled out! Can you see if it works better now?
Apr 26, 2021, 8:34 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.