Validation Error on datastore_search when sorting timestamp fields #4288
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
CKAN Version if known (or site URL)
2.7+
Please describe the expected behaviour
The datastore_search API should be able to perform a distinct or sort on fields with a timestamp data type. A data table or data explorer resource view should be able to reorder rows based on a timestamp field.
Please describe the actual behaviour
A validation error is returned from the datastore_search API when performing a distinct or sort on fields with a timestamp data type. The data table and data explorer view can't reorder rows based on a timestamp field.
The problem seems to be that timestamps are converted to char than to json before sorting.
https://github.com/ckan/ckan/blob/ckan-2.7.3/ckanext/datastore/backend/postgres.py#L1726-L1729
What steps can be taken to reproduce the issue?
Call the datastore_search endpoint with distinct=true and sorting on a timestamp field.
/api/3/action/datastore_search?resource_id={resource_id}&fields="DateOpened"&sort="DateOpened"&distinct=true
Returned Statement
Returned Validation Error