fix: honor HasConversion when a property has a HasQueryName alias - #107
Merged
Merged
Conversation
The filter parser replaces a query name with the property path before it parses. The HasConversion lookups then searched by query name, so they missed the configuration. The filter then failed or returned the wrong rows. The conversion lookups now use the property path. The fix also corrects four related faults in the same code path: - A null literal on a converted property compares against null. Before, the parser built a value from the text "null". - A converted Nullable<T> struct is built from its underlying type. - Guid string operators pass the string expression to the right side. - Property lists use the resolved member path, so a lowercase path still finds the conversion. Closes #106
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
Fixes #106. When a property has
HasQueryNameandHasConversion, a filter on the alias ignored the conversion. For a struct, the parser threwUnsupported value. In other cases, the filter returned the wrong rows.Root cause
ParseFilterreplaces each query name with its property path before it parses. The conversion lookups inFilterParserthen calledGetPropertyInfoByQueryNamewith this property path. When the alias and the path differed by more than case, the lookup missed the configuration.The fault is not specific to value types. The reference-type example in the issue worked only because
emailandEmaildiffer by case alone. An alias such asmailon a reference type failed too.Changes
All changes are in
QueryKit/FilterParser.cs:CreateRightExprand the two lookups in the member expression builder useGetPropertyInfo(propertyPath).nullliteral on a converted property compares against a typed null. Before, the parser builtnew EmailAddress("null")and returned no rows. With an alias, it threw.Nullable<T>struct is built from its underlying type, then converted toT?.@=) pass the converted string expression toCreateRightExpr. Before, a Guid withHasConversion<string>()threwExpression of type 'System.Guid' cannot be used for parameter of type 'System.String'.(id) == "2") use the resolved member path for the conversion lookup. As a result, a lowercase path still finds the conversion.Tests
QueryKit.UnitTests/HasConversionTests.cs(17 tests) covers structs, reference types, nested properties, a child of a converted parent, property lists, nullable structs, null literals, and Guid string operators. Most cases run with and without an alias.QueryKit.IntegrationTests/Tests/HasConversionTests.cscover an alias onEmail, the property path when an alias is set,Email.Valuewith an alias,nullwith an alias, the ownedPhysicalAddress.PostalCodewith and without an alias, and Guid@=with an alias.main, 11 of the new unit tests and 5 of the new integration tests fail. The other new tests are guards for cases that already work.End-to-end check
Each filter ran through
ApplyQueryKitFilteron an in-memory list and on Postgres through EF Core 10. The model has a converted structCode, a converted recordContact, and aGuidId. In every case, the in-memory list and Postgres gave the same result.mainsku == "BEEF-2"skuonCodeUnsupported value 'BEEF-2' for type 'RecipeCode'WHERE r."Code" = 'BEEF-2'sku != "BEEF-2"skuonCodeWHERE r."Code" <> 'BEEF-2'Code == "BEEF-2"skuonCodeCode == "BEEF-2"mail == "julia@example.com"mailonContactUnsupported value 'julia@example.com' for type 'ChefEmail'WHERE r."Contact" = 'julia@example.com'mail == nullmailonContactUnsupported value 'null' for type 'ChefEmail'WHERE r."Contact" IS NULLContact == nullWHERE r."Contact" = 'null'WHERE r."Contact" IS NULLidentifier @= "000000000002"identifieronIdId @= "000000000002"ArgumentExceptionWHERE r."Id"::text LIKE '%000000000002%'Out of scope
This change does not affect these separate, older faults:
(wrappedid) == "2"throwsUnknownFilterPropertyException. The alias rewrite needs an operator after the name.Items.Select(i => i.Contact)): no conversion lookup occurs, with or without an alias.