Fix parse of filter rules for boolean fields into SQL query #16982
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.
Fix how filter rules for boolean fields, as given in smart playlist files (.xsp), custom node files(.xml) and JSON API data requests, are converted into SQL queries. In particular correctly handle "is", "isnot", "contains" and "doesnotcontain" operators with value true or false.
It is far from intuitive how filter rules for boolean fields should be entered. Of course operators "true" and "false" naturally work with boolean fields e.g.
a) in xml (for smartplaylists and custom nodes)
<rule field="compilation" operator="true">
<rule field="compilation" operator="false">
b) in JSON
"filter": { "field": "compilation", "operator": "true", "value": "any dummy value here"}
"filter": { "field": "compilation", "operator": "false", "value": "any dummy value here"}
Notice that the JSON schema forces all filter rules to have a "value" property regardless of operator hence
"filter": { "field": "compilation", "operator": "true"}
is invalid.However it is reasonable to expect to be able to use
<rule field="compilation" operator="is"> <value>true</value> </rule>
or
"filter": { "field": "compilation", "operator": "is", "value": "true"}
These are valid rule input formats, but an incorrect SQL query is formed as a consequence and the data is not filtered in the way the user expects.
This PR ensures that for boolean fields the SQL created with operators "is" or "contains" and value "true", or operators "isnot" or "doesnotcontain" and value "false" will result in the same SQL as
operator="true"
. Likewise that created with operators "is" or "contains" and value "false", or operators "isnot" or "doesnotcontain" and value "true" will be the same as withoperator="false"
An example test smart playlist is follows (you need a music library with some albums flagged as compilations
Equilvalent JSON request
Bump patch version of JSON API as change to internal implementation but not to the API definition.