๐Ÿ”ฎ Sanity Create is here. Writing is reinvented. Try now, no developer setup

Issue with article sorting by publishedAt date is resolved after a quick fix.

17 replies
Last updated: Feb 9, 2021
When fetching articles sorted by
publishedAt
date ordered DESC, results are somewhat jumbled with some of the articles that should be at the end of the list are being inserted at the beginning. The results in the screenshot start with the latest articles: 2021, then 2019 then 2021 again.
Feb 9, 2021, 10:16 AM
Thanks for reporting, Alex! Could you try wrapping
publishedAt
in
dateTime()
to see if that makes a difference, even if it slows down the query?
Feb 9, 2021, 10:25 AM
Thanks for the quick response but which
publishedAt
do I wrap with
dateTime()
? Not sure where to put it.
Feb 9, 2021, 10:31 AM
Apologies, I assumed you were using GROQ here, which doesn't make sense given the channel name and screenshots you shared ๐Ÿ˜‰ In that case, it'd have been like this:
order(dateTime(publishedAt) desc)
. Not here though.
We'll try to reproduce the issue on our end.
Feb 9, 2021, 10:34 AM
I see. I hope this get resolved soon. It's breaking the pagination of our site.
Feb 9, 2021, 10:37 AM
Could you add the document IDs to the query to verify that these are all published documents, including the ones that wrongly show up in the list?
Feb 9, 2021, 10:38 AM
Also, are you seeing correct results when ordering by
_createdAt
or
_updatedAt
?
Feb 9, 2021, 10:38 AM
Here with
_id

Yes, results seem to be accurate when ordered by
_createdAt
.
Feb 9, 2021, 10:42 AM
Interestingly, the articles jumbled in seems to be the ones I migrated from Wordpress with their own custom
_id
.
Feb 9, 2021, 10:43 AM
But that shouldn't affect the order, right?
Feb 9, 2021, 10:44 AM
Woops, wrong screenshots.
Feb 9, 2021, 10:46 AM
That's odd indeed. It shouldn't affect the order, but it does stand out that these have timestamps ending on 000Z, which perhaps were set slightly differently even if the distinction between the two doesn't surface in these results.
Could you compare an imported article with one of the others and check if their
publishedAt
values have identical formats when inspecting their raw JSON in the studio?
Feb 9, 2021, 10:54 AM
Here.
Some of the imported articles'
publishedAt
were manually set using Sanity's built-in datepicker.
Feb 9, 2021, 11:17 AM
You can see the jumbled results here https://opinyon.net/sections/opinion and here
http://opinyon.net/sections/entertainment
Everything was fine yesterday though. The imported articles were imported 2 weeks ago and we haven't made any changes with our queries since then.
Feb 9, 2021, 11:21 AM
Thanks for the additional details Alex. I can confirm that this is a regression on our side, and the back-end team are looking into it. Started late yesterday/early today. Will keep you updated here.
Feb 9, 2021, 11:45 AM
I see. I guess I'll sort by
_createdAt
at the moment. Thank you for help.
Feb 9, 2021, 11:48 AM
Hi again Alex, our back-end team just pushed a fix to production that should resolve these ordering issues on datetime fields. Please let me know if ordering by
publishedAt
now works properly.
Feb 9, 2021, 3:23 PM
Hi Peter, it's now working fine again. Thank you for the swift fix!
Feb 9, 2021, 7:43 PM

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?