Repository navigation
fix(sort): reject a sort on a collection property - #206
Merged
Merged
Conversation
A sort on a collection property passed the parse and failed when the query ran: InvalidOperationException in memory, and an EF translation error for a navigation collection. ApplyQueryKitSort now throws SortParsingException for a property that implements IEnumerable<T>, except string and byte[]. Postgres can order by an array column, so a sort such as Tags worked there before. The same sort failed in memory, and the order has no clear meaning, so QueryKit now rejects it on every provider. Fixes #205
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.
Fixes #205
Problem
A sort on a collection property passed the parse, then failed when the query ran:
Ingredients(navigation collection)InvalidOperationExceptionInvalidOperationException(EF cannot translate it)Tags(List<string>,text[])InvalidOperationExceptionORDER BY r."Tags"Change
SortParserthrowsSortParsingExceptionwhen the sort key is a collection: any type that implementsIEnumerable<T>, exceptstringandbyte[]. The message is "Parsing failed during sorting. 'Tags' is a collection, and a collection has no single sort order." It names the query name that the caller sent.byte[]stays sortable, because a database sorts it as one binary value, for example a SQL Server rowversion.PreventSort()is still ignored with no error. The check runs after the prevent check.SortParsingExceptiondoes not change.Behavior change: a sort on a Postgres array column, for example
Tags, worked before and now throwsSortParsingException. A collection has no single sort order, and the same sort failed in memory and on a DTO projection.Tests
QueryKit.UnitTests/CollectionSortTests.cs:List<T>,IReadOnlyList<T>,HashSet<T>, arrays, a number list, a navigation collection, and a nested path (Parent.Tags). Alsodesc, the-prefix, a second sort key,ApplyQueryKit, a query name,PreventSort(), a string, andbyte[]. Before the fix, 12 cases failed.DatabaseSortingTests:Tags,Tags desc, andIngredientson Postgres throwSortParsingException.Tags,Labels desc,Ingredients, andTitle, TagsthrowSortParsingExceptionon both targets.Titlestill sorts.