fabric8-services / fabric8-wit

wit stands for Work Item Tracker
http://devdoc.almighty.io/
Apache License 2.0
45 stars 86 forks source link

Bad Parameter error on trying to update workitem with Integer type field #2123

Open jarifibrahim opened 6 years ago

jarifibrahim commented 6 years ago

Expected behavior

PATCH request on /api/workitem/{wi_id} for workitem type Epic (or any other type with a field of type Integer) should update the field value. Example request

curl -X PATCH \
    -H "Authorization: Bearer $tkn" \
    -d '{
        "data": {
            "attributes": {
                "business_value": 12,
                "version": 1
            },
            "id": "312c3082-e2ec-4642-a316-3ff4928bf0dd",
            "type": "workitems"
        }
    }' \
    http://localhost:8080/api/workitems/312c3082-e2ec-4642-a316-3ff4928bf0dd

Response is

{"errors":[{"code":"bad_parameter","detail":"Bad value for parameter 'business_value': '12'","status":"400","title":"Bad parameter error"}]}

Actual behavior

PATCH request on /api/workitem/{wi_id} for workitem type Epic (or any other type with a field of type Integer) should update the field value.

jarifibrahim commented 6 years ago

It looks like the type of value for the field business_value in ctx.payload is float64 instead of int https://github.com/fabric8-services/fabric8-wit/blob/79ce6a9abf2c8f2e2c6ac1e3f86c0046fd70a18f/controller/workitem.go#L86-L87 and hence the conversion fails at the following lines https://github.com/fabric8-services/fabric8-wit/blob/79ce6a9abf2c8f2e2c6ac1e3f86c0046fd70a18f/workitem/simple_type.go#L71-L74 because valueType.Kind() is float64 instead of int/int64.

kwk commented 6 years ago

It looks like the type of value for the field business_value in ctx.payload is float64 instead of int

@jarifibrahim what happens when you update the business value with a float then?

jarifibrahim commented 6 years ago

@jarifibrahim what happens when you update the business value with a float then?

It doesn't work for float as well. The following conversion logic fails https://github.com/fabric8-services/fabric8-wit/blob/79ce6a9abf2c8f2e2c6ac1e3f86c0046fd70a18f/workitem/simple_type.go#L71-L74