Repository navigation
Inconsistencies with MRI regarding hashes and arrays affecting rails #411
Description
Activity
Please avoid aggregating disparate issues into one ticket. It makes discussion really confusing. I can fixed the first issue (since it's a simple fix to align error message more closely) with aa2e98c, so there is no need to split this one.
I apologize for aggregating the issues and thanks for the fix. Should we add a spec for this case in ruby spec or it's not worth the effort ?
It's not necessary. It is a bad idea to rely on error message, but I guess there is no distinction between this kind of
RuntimeError(attempts to modify frozen object, aHash) and others.Thanks for fixing those bugs.
I have a problem though. The reason I opened this issue is to discuss which implementation is wrong and try to fix it. The changes you pushed aren't tested which means that someone can change this behavior without knowing in the future.
The second issue, is that the ruby documentation is not right, so either MRI has to change to match the docs or JRuby has to change its behavior (which is the path you chose) and the docs have to be fixed.
- added a commit that references this issue
on Nov 26, 2012 @jvshahid Oh. I see what you are saying now. I apologize for the confusion. I think this is an MRI bug, after all. I'm going to revert the changes, and open a bug with MRI.
- added a commit that references this issue
on Nov 26, 2012 By the way, the test should go into RubySpec.
Looks like the behavior change was explicit and intentional, so we'll need to follow suit with MRI here.
I expect MRI to retain its current behavior and correct the documentation. Once we have that confirmed, I will re-apply the fix, and propose the spec to RubySpec (or inherit MRI's new test).
- added a commit that references this issue
on Nov 26, 2012 Re-pushed the fix. Spec will be pushed to RubySpec.
Thanks.
- added 4 commits that reference this issue
on Dec 3, 2012
Hi there,
I'm currently working on a drop in replacement gem for ruby-pg under JRuby. While running the active record test suite on the gem, I realized the following inconsistencies between JRuby and MRI:
Under MRI this code will throw the following error:
Under JRuby it will throw the following:
What's relevant here is the case of
Hashvs.hash. Surprisingly, there's a test in rails that test the actual error message and it's not case insensitive. I guess the question now is what's the right course of action here.First the bug, is in Array::delete. Although the ruby docs say that Array::delete(obj) will return obj if an object was found (and deleted) that's equal to obj. But the actual implementation returns the last object in the array that was equal to obj instead of obj (as seen in the source code and docs here). On the other hand JRuby do the right thing and return obj. I know, I said JRuby is doing the right thing, but it's still a difference between the two implementations and MRI is the defacto standard. I also don't know what's the right course of action which is why I'm posting this here to discuss.
A test case to explain the difference in behavior is:
Output under MRI:
27 should equal 28Under JRuby:
28 should equal 28In case you were wondering where this is relevant or someone had the same problem in rails. The problem is in
activerecord/lib/active_record/associations/collection_association.rb:422where the code tries to merge in memory records that could possibly be modified with records that were just retrieved from the db (as shown below). In MRImem_recordwill hold the memory record since we're deleting from thememoryarray, while JRuby will return the object we're trying to delete which is the persisted record. The symptom of this bug is that you loose your memory modifications if you don't save the record to the db, since everytime you merge the persisted data will override what's in memory.Sorry for this lengthy issue, I tried to be thorough as much as I can. I'm happy to write the specs in ruby-specs and send a patch to make the spec pass. I don't know which implementation should be fixed and want everyone to be on the same page (including the MRI guys if this will involve a change in their implementation) before I go on.