fix: return an invalid error for sort input that is not a string or list - #2947
Merged
zachdaniel merged 1 commit intoSep 17, 2026
Merged
Conversation
|
Thanks for picking this up. I ran the reproduction suite from https://github.com/grempe/ash-fuzz-repros with |
Contributor
|
🚀 Thank you for your contribution! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #2941.
Ash.Sort.parse_input/3has clauses for a string, an atom, a list andnil, so any other value (5,%{},%{"title" => "asc"}) raisesFunctionClauseError. A list is accepted, but an element that is neither a field name nor a{field, order}tuple (e.g.[%{"field" => "title"}]) falls throughparse_sort/4intoAsh.Resource.Info.attribute/2, which raises the same way.Ash.Query.filter_input/2puts anInvalidFilterValueon the query for a malformed shape;sort_input/2now does the equivalent.Ash.Error.Query.InvalidSort(class:invalid, field:sort), alongside the existingInvalidSortOrder.parse_input/3gets a final clause returning{:error, %InvalidSort{}}.parse_sort/4clause is guarded tobinary | atom | struct(the shapesget_field/5handles), with a final clause returningInvalidSortfor anything else.Ash.Query.sort_input/2then adds that error to the query instead of raising.Tests:
test/sort/sort_test.exscoverssort_inputwith5,%{},%{"title" => "asc"}and[%{"field" => "title"}], andparse_inputwith5and a map. Onmainthe foursort_inputcases raiseFunctionClauseError(Ash.Sort.parse_input/3/Ash.Resource.Info.attribute/2); with the change they pass. Full suite: 4149/4150 — the one failure (Mix.Tasks.Ash.Gen.ResourceTest"generates resource with custom base") fails identically onmainwithout this change.mix format --check-formattedandmix credo --strictclean on the touched files.Contributor checklist
Leave anything that you believe does not apply unchecked.