Defect #37008

Custom query

Added by Eugene Lastname 2 months ago.

Status:NewStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Search engine
Target version:-
Resolution: Affected version:

Description

We have made a query for our entities, inheriting the basic redmine Query.
But faced a problem with using custom methods sql_for_['field_name']_field

This is how the filters are defined


def sql_for_something_field(field, operator, values)
   sql_for_field(field, operator, values, ::StateContract.table_name, :identifier)
end

And during the exploitation found that filters with the operator "!*" and string data type do not always work correctly.
All next filters stop working.

Here is the resulting SQL

WHERE ( table1.field1 IS NULL OR table1.field1 = '' AND (table2.id IN (1000)))

The problem is the missing brackets around

table1.field1 IS NULL OR table1.field1 = ''

After some digging, I found (app/models/query.rb:989)

filters_clauses << send(method, field, operator, v)

Which did not expose brackets for the custom filter.

I believe that filters, even custom ones, should be isolated.

Please replace

filters_clauses << send(method, field, operator, v)

on the

filters_clauses << '(' + send(method, field, operator, v) + ')'

Note
For most filters, your implementation is not a problem
But for the operator "!*" with the string data type in the query, an OR is set, which breaks the query.

Also available in: Atom PDF