Open gazjones00 opened 1 year ago
@gazjones00
I encountered the same issue when attempting to sort by date/number. I wasn't able to sort by number and the date isn't sourced from a metaobject JSON.
As a temporary workaround, I defined the date as a string within the metaobject. I then used regex validation to ensure user input adheres to the 'yyyy-mm-dd' format. By doing this, I was able to sort the dates alphabetically, and this approach successfully resolved the issue for me.
I hope this helps someone else facing a similar problem, but it'd be great if the core issue with sorting numerical types could be addressed. Thanks for this issue!
Seems entirely silly that we cannot sort by date
type in a metaobject
Summary:
When trying to sort a Metaobject that contains several metafields, including
order_index
of typenumber_integer
, the Liquid engine throws an error that sayscannot sort values of incompatible types
. The sorting works perfectly well when sorting bysingle_line_text_field
orstring
, but not with a numerical value.Details:
We have a Metaobject defined for a size guide, containing a metafield
order_index
of typenumber_integer
. We are trying to sort this Metaobject byorder_index
but are encountering an error.Code sample:
The error seems to be originating from this line: https://github.com/Shopify/liquid/blob/0b9318222bcc09681e52fd5b8e70262274e673bf/lib/liquid/standardfilters.rb#L923
Inside the sort function here: https://github.com/Shopify/liquid/blob/0b9318222bcc09681e52fd5b8e70262274e673bf/lib/liquid/standardfilters.rb#L355
Steps to Reproduce:
order_index
of typenumber_integer
.cannot sort values of incompatible types
.Expected Behavior:
The Metaobject should be sorted based on the
order_index
field without errors.Actual Behavior:
Throws error
cannot sort values of incompatible types
.Additional Information:
single_line_text_field
orstring
.Thank you for taking the time to look into this issue. I would love to hear any insights or solutions.