Skip to content

Can't override all types of default parameters #7

@erikw

Description

@erikw

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=Erik

to 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=$null

This 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/info

returns

{
    ...
    "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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions