In some case ActiveResource fails to handle serialized attributes with Ruby 1.9 and crashes #2585
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
First of all, this is my first attempt at contributing to rails. I tried to follow the Rails guide, but I might be off. Feel free to give me guidelines ^^
I'll take the example of a blog with posts & comments to illustrate the issue.
ActiveResource takes all attributes of an object to create an object out of it. For instance if the JSON passed around is:
It will create the correct
Comment
object associated with thePost
. This works fine.The problem is when we try to pass via ARes an object with serialized attributes. Let's say that we have:
with updates defined as such:
[{:user_updating_id => :update_date_to_i}, ...]
We could now have something like that:
The problem arise when we try to do a .to_sym on the parameters. In 1.8.7 it would just return nil:
But in 1.9.2 it crashes:
I'm suggesting skipping attributes that are not valid to have the same behavior between Ruby 1.8.7 and 1.9.2. I inspired myself from the fact that we "
next
" blank attributes, so why not unsuitable ones?This is not ideal, since it would be better to be able to determine if something is a serialized attribute or another model embeded and then have a different logic, but at least this would prevent ARes from crashing for Ruby 1.9.2 as it does right now if we have the situation detailed above.
Let me know if you need more detail or if you need something else to accept this patch!