-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Setup
There is a service using restler. It has a resource, e.g. BookResource, which has overridden ServiceResource<V, K>.getServiceQueryParams() to add a default query parameter e.g. type=null.
Thus you can retrieve books like
GET /book/-;Author=Erikto get books by Erik (which where type==null).
How to trigger the bug
We want to override the default value, and get books where type != null, so we try
GET /book/-;type__ne=$nullThis does not work, you don't get the expected results. Adding /info to the query reveals that the real query was
GET /book/-;type__ne=$null/inforeturns
{
...
"urlPart": "/book/-;type=$null;type <>=$null"
...
}, so the default value was not overridden!
Where the problem comes from
The problem is that in restdsl.util.RequestUtil.parseRequest() we use parsedQueryField.getFullCriteria() as the key in our multimap, and in this case the key for our queryparam type__ne=$null is type <>. The default value for "type" is stored with the key type.
The effect of this is that in restdsl.queries.ServiceQuyery:applyServiceQueryParams() where we merge the default parameters to the user provided ones, that we don't replace them as the key for the user provided query parameter was type <> and not type.
Possible solution
Use
String fieldNameWithoutConditions = parsedQueryField.getFieldName();as the key in the multimap instead. Then the default value would get properly replaced.
The implication is that this not a backwards compatible fix, as it changes how queries are made => version bump?