Issue with method max from enumerable when applied to has_many association
--------------------------------------------------------------------------
Key: JRUBY-3099
URL: http://jira.codehaus.org/browse/JRUBY-3099
Project: JRuby
Issue Type: Bug
Affects Versions: JRuby 1.1.5
Environment: Linux wheat 2.6.27-7-generic #1 SMP Fri Oct 24 06:42:44
UTC 2008 i686 GNU/Linux
java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Server VM (build 11.0-b15, mixed mode)
*** LOCAL GEMS ***
actionmailer (2.2.0, 2.1.2, 2.1.1)
actionpack (2.2.0, 2.1.2, 2.1.1)
activerecord (2.2.0, 2.1.2, 2.1.1)
activeresource (2.2.0, 2.1.2, 2.1.1)
activesupport (2.2.0, 2.1.2, 2.1.1)
cgi_multipart_eof_fix (2.5.0)
daemons (1.0.10)
fastercsv (1.4.0)
fastthread (1.0.1)
gem_plugin (0.2.3)
linecache (0.43)
money (1.7.1)
mongrel (1.1.5)
mysql (2.7)
parseexcel (0.5.2)
paypal (2.0.0)
rails (2.2.0, 2.1.2, 2.1.1)
rake (0.8.3, 0.8.2, 0.8.1)
rmagick (2.7.0, 2.6.0)
ruby-debug-base (0.10.2, 0.10.1)
ruby-debug-ide (0.3.1, 0.3.0, 0.2.1)
sqlite3-ruby (1.2.4)
Reporter: rienko
Assignee: Thomas E Enebo
Priority: Minor
Attachments: array_max_bug.tbz
I've detected a weird behaviour on the max(&block) method from
enumerable when invoked on a has_many relation of rails.
The attachment file contains a rails environment where the
issue can be tested.
The following code exposes the bug ,
ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]
[EMAIL PROTECTED]:~/test$ /usr/bin/ruby script/console
Loading development environment (Rails 2.1.2)
>> >> u = User.first
>> >> u.accounts.max{|x,y| puts x.class; puts y.class; -1}
Account
Account
Account
Account
Account
Account
Account
Account
jruby 1.1.4 (ruby 1.8.6 patchlevel 114) (2008-10-29 rev 7939) [i386-java]
[EMAIL PROTECTED]:~/test$ jruby script/console
>> >> User.first.accounts.class
=> >> User.first.accounts.max{|x,y| puts x.class; puts y.class; -1}
Array
NilClass
Array
NilClass
Array
NilClass
Array
NilClass
>> >> User.first.accounts.max{|x,y| puts x.inspect; puts y.class; -1}
[#<Account id: 2, title: nil, user_id: 1, created_at: "2008-10-29
13:54:29", updated_at: "2008-10-29 13:54:29">, #<Account id: 1, title:
nil, user_id: 1, created_at: "2008-10-29 13:54:20", updated_at:
"2008-10-29 13:54:20">]
NilClass
[#<Account id: 3, title: nil, user_id: 1, created_at: "2008-10-29
13:54:30", updated_at: "2008-10-29 13:54:30">, #<Account id: 1, title:
nil, user_id: 1, created_at: "2008-10-29 13:54:20", updated_at:
"2008-10-29 13:54:20">]
NilClass
[#<Account id: 4, title: nil, user_id: 1, created_at: "2008-10-29
13:54:30", updated_at: "2008-10-29 13:54:30">, #<Account id: 1, title:
nil, user_id: 1, created_at: "2008-10-29 13:54:20", updated_at:
"2008-10-29 13:54:20">]
NilClass
[#<Account id: 5, title: nil, user_id: 1, created_at: "2008-10-29
13:54:30", updated_at: "2008-10-29 13:54:30">, #<Account id: 1, title:
nil, user_id: 1, created_at: "2008-10-29 13:54:20", updated_at:
"2008-10-29 13:54:20">]
NilClass
=> #<Account id: 1, title: nil, user_id: 1, created_at: "2008-10-29
13:54:20", updated_at: "2008-10-29 13:54:20">
If we clone the array, them max behaves has MRI,
so User.first.account.clone.max{|x,y| puts x.inspect; puts y.class; -1},
yields the same results on both MRI and JRUBY.
I suspect some association proxy in rails may be the culprit.
I've tested the issue against trunk, but I remember a fellow developer
hitting the same bug a few months ago (at the time I lacked the time to
investigate the issue), so older versions should also be affected.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email