This project is archived and is in readonly mode.
[PATCH] json validations errors for ActiveResource
Reported by Fabien Jakimowicz | February 13th, 2009 @ 12:18 AM | in 2.3.6
ActiveResource can interpret validations errors from xml body, but not from json and even worse : he tries to interpret json output as xml and parse it.
This patch adds json support for validations errors based on the work of Rick Olson. You can render errors in json like this : render :json => @person.errors.to_json, :status => 422
Comments and changes to this ticket
-
Fabien Jakimowicz March 30th, 2009 @ 01:04 AM
- Tag changed from activeresource, json, patch, validations to activeresource, active_resource, json, patch, validations
-
Fabien Jakimowicz March 30th, 2009 @ 01:04 AM
- Tag changed from activeresource, active_resource, json, patch, validations to activeresource, active_resource, json, patch, validation, validations
-
Fabien Jakimowicz April 18th, 2009 @ 12:01 AM
- Tag changed from activeresource, active_resource, json, patch, validation, validations to 2-3-stable, activeresource, active_resource, json, patch, validation, validations
updated patch for 2-3-stable branch.
-
Samsonov Ivan July 8th, 2009 @ 04:20 PM
Our company faces the same problem. Why is this patch not accepted?
-
Fabien Jakimowicz July 27th, 2009 @ 12:04 PM
I tried to contact rails-core mailing list, but nobody answers. I also try to contact directly a member of the rails-core team who told me the patch seems good and should be applied within 2 weeks ... but that was 2 months ago and he does not answer me anymore.
I checked with both 2.3 and 3.0 branches and it still applies cleanly.
Maybe if you can move things on the mailing list, you can have this patch applied.
-
Fabien Jakimowicz July 27th, 2009 @ 12:13 PM
- Tag changed from 2-3-stable, activeresource, active_resource, json, patch, validation, validations to 2-3-stable, 2.3.x, 2.x, 3.0, activeresource, active_resource, json, patch, validation, validations
-
Rizwan Reza August 9th, 2009 @ 12:28 AM
- Tag changed from 2-3-stable, 2.3.x, 2.x, 3.0, activeresource, active_resource, json, patch, validation, validations to 2-3-stable, 2.3.x, 2.x, 3.0, activeresource, active_resource, bugmash, json, patch, validation, validations
verified
+1 This applies to 2-3-stable cleanly but not master.
-
Elad Meidar August 9th, 2009 @ 04:03 AM
Patch applies and tests pass on 2-3-stable
Patch does not apply on master.
-
Fabien Jakimowicz August 9th, 2009 @ 03:01 PM
I updated patch for both 2-3-stable and master branches.
-
Fabien Jakimowicz August 9th, 2009 @ 04:02 PM
- Title changed from json validations errors for ActiveResource to [PATCH] json validations errors for ActiveResource
-
Elad Meidar August 9th, 2009 @ 06:07 PM
+1 Verified, +1 on 2-3-stable patch => applies and all tests pass, +1 on master patch => applies and all tests pass
-
David Trasbo August 9th, 2009 @ 07:53 PM
-1
Both patches don't apply and needs to be updated respectively.
-
Fabien Jakimowicz August 9th, 2009 @ 08:00 PM
david trasbo: this is weird, I just test it and was able to apply it to both branches. How does it fail ?
-
Josh Nichols August 10th, 2009 @ 04:52 AM
+1, I like the cut of this patch, for it brings consistency between xml and json behavior with regards to validation errors.
Verified to apply and pass tests on master and 2-3-stable.
-
Repository August 10th, 2009 @ 06:42 AM
- State changed from new to committed
(from [797588543ed70b4c5dcf51d7f1e4a77082172f0b]) Add support for errors in JSON format.
[#1956 state:committed]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
http://github.com/rails/rails/commit/797588543ed70b4c5dcf51d7f1e4a7... -
Repository August 10th, 2009 @ 06:42 AM
(from [c3da22c042d083b788fd35ce7a25e3d8933bcae6]) Add support for errors in JSON format.
[#1956 state:committed]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
http://github.com/rails/rails/commit/c3da22c042d083b788fd35ce7a25e3... -
Jeremy Kemper August 10th, 2009 @ 06:42 AM
- Tag changed from 2-3-stable, 2.3.x, 2.x, 3.0, activeresource, active_resource, bugmash, json, patch, validation, validations to 2-3-stable, 2.3.x, 2.x, 3.0, activeresource, active_resource, json, patch, validation, validations
- Milestone changed from 2.x to 2.3.4
-
Jeremy Kemper September 17th, 2009 @ 07:23 PM
- Milestone changed from 2.3.4 to 2.3.6
- State changed from committed to open
- Assigned user set to Jeremy Kemper
A change to ActiveResource::Validations was introduced in 2.3.4 which adds support for JSON errors:
This is looking for an exact match on Content-Type 'application/xml'. If, for example, the returned Content-Type is 'application/xml; charset=utf-8' then the error response is ignored.
-
Repository September 17th, 2009 @ 07:53 PM
- State changed from open to committed
(from [1488c6cc9e6237ce794e3c4a6201627b9fd4ca09]) Fix brittle content-type check. [#1956 state:committed] http://github.com/rails/rails/commit/1488c6cc9e6237ce794e3c4a620162...
-
Repository September 17th, 2009 @ 07:53 PM
(from [b5dd1b659987bb6117c0f1657e66dc395cfbed5e]) Fix brittle content-type check. [#1956 state:committed] http://github.com/rails/rails/commit/b5dd1b659987bb6117c0f1657e66dc...
-
Gabe da Silveira October 2nd, 2009 @ 07:55 PM
This patch introduced a regression my app's tests because our activeresource mocks did not set a content-type header. This was easy enough to fix once I debugged it, but it was pretty nasty to track down since the result is simply that the error messages are ignored and save returns true and the object appears valid with no trace of what happened without debugging deep into ActiveResource. Even though in production this case ought to never happen, in tests it's the default with no indication that you would need to set a Content-Type header.
The bottom line in my opinion is that any case where a 422 response is returned, the object should end up as invalid.
Although I'm not sure that defaulting to XML is "correct" or complete, I think we should do it to maintain backwards compatibility.
At the very least the ActiveResource::HttpMock documentation should show an example of stubbing an error.
What does everyone think?
-
Jatinder Singh October 27th, 2009 @ 07:09 AM
To avoid the problem faced by Gabe, the solution is to verify the format of ARes rather than Content-Type header for the remote errors.
I've attached patches for master and 2-3-stable.
-
Christian Seiler January 4th, 2010 @ 05:31 PM
Another (slightly) related problem with ActiveResource and validations:
https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets... -
Jeremy Kemper January 27th, 2010 @ 04:16 AM
- State changed from open to incomplete
Jatinder - tests?
-
Jatinder Singh January 27th, 2010 @ 11:44 PM
Alright I've attached patches for master and 2-3-stable, with tests.
-
Repository January 28th, 2010 @ 02:28 AM
- State changed from incomplete to committed
(from [158e7b63ab83dbcb9cdc7f951be920faf16fe3c0]) Use format of ARes rather than content-type of remote errors to load errors.
[#1956 state:committed]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
http://github.com/rails/rails/commit/158e7b63ab83dbcb9cdc7f951be920... -
Repository January 28th, 2010 @ 02:28 AM
(from [e87748869af238fe6bcb78e8d9a8d2bbc3734039]) Use format of ARes rather than content-type of remote errors to load errors.
[#1956 state:committed]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
http://github.com/rails/rails/commit/e87748869af238fe6bcb78e8d9a8d2... -
Jeff Kreeftmeijer November 8th, 2010 @ 08:22 AM
- Tag cleared.
- Importance changed from to Low
Automatic cleanup of spam.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 1956 [PATCH] json validations errors for ActiveResource [#1956 state:committed]
- 1956 [PATCH] json validations errors for ActiveResource [#1956 state:committed]
- 3222 ActiveResource is not extracting errors from an XML response if the Content-Type is 'application/xml; charset=utf-8' Reopened #1956 with this issue.
- 1956 [PATCH] json validations errors for ActiveResource (from [1488c6cc9e6237ce794e3c4a6201627b9fd4ca09]) Fix bri...
- 1956 [PATCH] json validations errors for ActiveResource (from [b5dd1b659987bb6117c0f1657e66dc395cfbed5e]) Fix bri...
- 3386 ActiveResource not picking up (validation) errors in 2.3.4 #1956
- 1956 [PATCH] json validations errors for ActiveResource [#1956 state:committed]
- 1956 [PATCH] json validations errors for ActiveResource [#1956 state:committed]