Jeff Scott Brown
2014-04-30 15:02:05 UTC
I think http://jira.grails.org/browse/GRAILS-11354 is a fairly serious problem. I think controllers which extends RestfulController are broken in a bad way in 2.3.8, and it is my fault (see below).
The createResource method in RestfulController looks like this:
protected T createResource(Map params) {
resource.newInstance(params)
}
A problem with this is that if the request contains a body, the params is an empty Map so the resource is not populated with with the expected values (the values from the body).
I haven’t gone through adequate testing yet but at least for simple cases, something like this works:
protected T createResource(Map params) {
T t = resource.newInstance()
bindData t, request
t
}
This all worked in 2.3.7 but is broken in 2.3.8. The commit that broke this was made by me. See https://github.com/grails/grails-core/commit/498853e4aca0efefd6c8a4e1a2befe8da77896f8. When I made that change I discussed it with Graeme and at that time Graeme said that he was sure that when he added the code I was removing there that there was a reason, but he couldn’t remember what it was. It seems he was right, but I think that the code I removed is probably not really what we want. The problem with that code is that if data binding is being done with params during a request that has a body, the params are ignored even though the code that initiated the binding explicitly bound using params, not the body. See the unit tests in the commit linked above. I think those are valid and describe what should happen for those scenarios.
I think it is probably incorrect that RestfulController does binding with params. I think if you bind with params, params should be used. I think if you bind with request and the request has the body, the body should be used, otherwise params should be used.
Related to this is http://jira.grails.org/browse/GRAILS-11263 which requests that we use both the body and params. I think that is easy enough to do but we need to decide which takes precedence if they both contain the same keys.
What say ye of all/any of that?
JSB
—
Jeff Scott Brown
***@gopivotal.com
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
The createResource method in RestfulController looks like this:
protected T createResource(Map params) {
resource.newInstance(params)
}
A problem with this is that if the request contains a body, the params is an empty Map so the resource is not populated with with the expected values (the values from the body).
I haven’t gone through adequate testing yet but at least for simple cases, something like this works:
protected T createResource(Map params) {
T t = resource.newInstance()
bindData t, request
t
}
This all worked in 2.3.7 but is broken in 2.3.8. The commit that broke this was made by me. See https://github.com/grails/grails-core/commit/498853e4aca0efefd6c8a4e1a2befe8da77896f8. When I made that change I discussed it with Graeme and at that time Graeme said that he was sure that when he added the code I was removing there that there was a reason, but he couldn’t remember what it was. It seems he was right, but I think that the code I removed is probably not really what we want. The problem with that code is that if data binding is being done with params during a request that has a body, the params are ignored even though the code that initiated the binding explicitly bound using params, not the body. See the unit tests in the commit linked above. I think those are valid and describe what should happen for those scenarios.
I think it is probably incorrect that RestfulController does binding with params. I think if you bind with params, params should be used. I think if you bind with request and the request has the body, the body should be used, otherwise params should be used.
Related to this is http://jira.grails.org/browse/GRAILS-11263 which requests that we use both the body and params. I think that is easy enough to do but we need to decide which takes precedence if they both contain the same keys.
What say ye of all/any of that?
JSB
—
Jeff Scott Brown
***@gopivotal.com
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email