Conversation
Title @= null built x.Title.Contains(null). In memory, the query threw ArgumentNullException when it ran. On Postgres, the query returned no rows. The same was true for _=, _-=, and their negations. The operators now throw QueryKitParsingException when the filter is parsed, on every target. BREAKING CHANGE: a null value on the right side of @=, _=, _-=, !@=, !_=, or !_-= (and their case-insensitive forms) throws QueryKitParsingException from ApplyQueryKitFilter. A database query with this filter returned no rows before. Use == or != to compare with null.
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.
Summary
This PR makes a
nullvalue with a case-sensitive string operator throwQueryKitParsingException. This is a breaking change. It is one of the six breaking changes that were removed from #114 so that main stays compatible with v1.14.2.Status: for later consideration. Do not merge this PR now. The captain decides on each breaking change separately. If this change is accepted, it needs a major version.
Main already has the null checks on the property (
left != null && ...). This PR adds onlyEnsureStringValueIsNotNulland its six calls.Old behavior (v1.14.2 and main)
Title @= nullbuildsx.Title.Contains(null).string.ContainsthrowsArgumentNullExceptionwhen the query is enumerated.The same is true for
_=,_-=, and their negations.New behavior
A
nullvalue on the right side of@=,_=,_-=,!@=,!_=, or!_-=throwsQueryKitParsingExceptionwhen the filter is parsed. The case-insensitive forms (@=*and more) also throw. This occurs before the query runs, for both memory and database queries.Example
Proof from the
verify-querykitharness:ArgumentNullExceptionQueryKitParsingException: "The '@=' operator does not accept a null value. Use '==' or '!=' to compare with null."WHERE FALSE)QueryKitParsingExceptionA null property still works with a string value.
Directions !@= "bake"returns Pancakes, Beef Stew, and Plain Water (nullDirections) on both targets.Justification
"Contains null" has no meaning, and v1.14.2 gives two different answers for it. The in-memory answer is an exception type that a consumer does not expect from a parser. The database answer is a silent empty result.
A client that sends this filter has an error, and the API must tell the client. A
QueryKitParsingExceptionat parse time lets the API return a 400 with a clear message. This is the same path as every other bad filter. The break is small: only a consumer that depends on the empty database result sees a change.Migration
Use
==or!=to compare with null.Tests
string_operator_with_null_value_throws_querykit_exception, with 8 cases.string_operator_with_null_value_throws_querykit_exception.dotnet test: 354 unit tests and 269 integration tests pass.