Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't override all types of default parameters #7

Open
erikw opened this issue Sep 29, 2017 · 0 comments
Open

Can't override all types of default parameters #7

erikw opened this issue Sep 29, 2017 · 0 comments

Comments

@erikw
Copy link

erikw commented Sep 29, 2017

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?

erikw pushed a commit that referenced this issue Nov 24, 2017
Always append ; as separator between ID-part and criteria-part for info
query URL part.

Fixes #7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant