This project is archived and is in readonly mode.
ActiveResource load method dies on Array contains Numeric elements
Reported by GrzesF | March 20th, 2009 @ 11:50 PM | in 2.x
Here is sample json which cause problem for ActiveResource load method:
{"id":13679082001,"referenceId":"homepage_main","name":"Main Video Homepage","shortDescription":null,
"videoIds":[13451141001,13460674001,13451144001,13460676001],"thumbnailURL":null,"filterTags":null,"playlistType":"EXPLICIT"}
The main problem is with Array element "video_ids":[13451141001,13460674001,13451144001,13460676001] while processing.
Load method raise exception:
ArgumentError: expected an attributes Hash, got 13451141001
from /Library/Ruby/Gems/1.8/gems/activeresource-2.3.2/lib/active_resource/base.rb:942:in `load'
from /Library/Ruby/Gems/1.8/gems/activeresource-2.3.2/lib/active_resource/base.rb:655:in `initialize'
from /Library/Ruby/Gems/1.8/gems/activeresource-2.3.2/lib/active_resource/base.rb:949:in `new'
from /Library/Ruby/Gems/1.8/gems/activeresource-2.3.2/lib/active_resource/base.rb:949:in `load'
from /Library/Ruby/Gems/1.8/gems/activeresource-2.3.2/lib/active_resource/base.rb:949:in `map'
from /Library/Ruby/Gems/1.8/gems/activeresource-2.3.2/lib/active_resource/base.rb:949:in `load'
from /Library/Ruby/Gems/1.8/gems/activeresource-2.3.2/lib/active_resource/base.rb:944:in `each'
from /Library/Ruby/Gems/1.8/gems/activeresource-2.3.2/lib/active_resource/base.rb:944:in `load'
from /Library/Ruby/Gems/1.8/gems/activeresource-2.3.2/lib/active_resource/base.rb:655:in `initialize'
from /Library/Ruby/Gems/1.8/gems/activeresource-2.3.2/lib/active_resource/base.rb:603:in `new'
from /Library/Ruby/Gems/1.8/gems/activeresource-2.3.2/lib/active_resource/base.rb:603:in `instantiate_record'
I think there should be additional case when there are Numeric elements in Array child. I assume json file is in valid format.
Is it a bug ? or am I wrong ? I've added some test to this case and made a patch(attached). It works for me.
Comments and changes to this ticket
-
CancelProfileIsBroken August 5th, 2009 @ 03:43 PM
- Tag changed from active_resource, load to active_resource, bugmash, load, patch
-
pjammer August 9th, 2009 @ 03:14 AM
+1 patch verified and works well with the tests. -1 for that json file and using it in the console. I create a mini app, loaded the patch up into it and pasted the contents of that json file into the console and it puked trying to read the hash.
>> m = {"id":"123445567890","referenceid":"homepage_main","videoIds":[13451141001,13460674001,13451144001,13460676001]} SyntaxError: compile error (irb):4: odd number list for Hash m = {"id":"123445567890","referenceid":"... ^ (irb):4: syntax error, unexpected ':', expecting '}' m = {"id":"123445567890","referenceid":"... ^ (irb):4: syntax error, unexpected ',', expecting $end m = {"id":"123445567890","referenceid":"homepage_main",... ^ from (irb):4 >>
i couldn't test further on the actual merit, but the tests passed using the patch.
-
Elad Meidar August 9th, 2009 @ 03:37 AM
+1 on patch, applies cleanly on 2-3-stable and master, logic makes sense.
-
Kamal Fariz August 9th, 2009 @ 03:46 AM
Just to add, bare numeric elements in an array is legal JSON according to JSONLint.
-
Jatinder Singh August 9th, 2009 @ 06:50 AM
+1 verified.
I came across this defect at work this week, when I was trying to load an ARes from attributes containing a serialized hash column.
-
Pratik August 9th, 2009 @ 11:18 PM
I don't like
attrs.dup rescue attrs
It should probably use Object#duplicable?.
-
Elad Meidar August 9th, 2009 @ 11:30 PM
Attached a fixed patch with #duplicable?, applies to master and 2-3-stable and passes tests
-
Tristan Dunn August 9th, 2009 @ 11:37 PM
+1
Elad's patch applies cleanly to master and 2-3-stable, with passing tests.
-
Repository August 9th, 2009 @ 11:40 PM
- State changed from new to resolved
(from [59c3b0d0deb8ddd83f20c8a66fde188aed74c51c]) Ensure ActiveResource#load works with numeric arrays [Grzegorz Forysinski, Elad Meidar]
[#2305 state:resolved]
Signed-off-by: Pratik Naik pratiknaik@gmail.com
http://github.com/rails/rails/commit/59c3b0d0deb8ddd83f20c8a66fde18... -
Repository August 9th, 2009 @ 11:40 PM
(from [e391c7a97cdefa172fcba214fb0a6cd3bd5b0bf4]) Ensure ActiveResource#load works with numeric arrays [Grzegorz Forysinski, Elad Meidar]
[#2305 state:resolved]
Signed-off-by: Pratik Naik pratiknaik@gmail.com
http://github.com/rails/rails/commit/e391c7a97cdefa172fcba214fb0a6c... -
Pratik August 9th, 2009 @ 11:52 PM
- Tag changed from active_resource, bugmash, load, patch to active_resource, load, patch
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
Tags
Referenced by
- 2305 ActiveResource load method dies on Array contains Numeric elements [#2305 state:resolved]
- 2305 ActiveResource load method dies on Array contains Numeric elements [#2305 state:resolved]