Calling collection attribute is returning string instead of collection
barberj opened this issue · comments
NoMethodError: undefined method `each_slice' for "123276":String
class SomeClass < Ohm::Model
collection :children, :SomeClass, :parent
end
x = SomeClass.new
x.children.map { |c| c.id }
Running in a multithreaded environment under sidekiq. Having troubles reproducing locally.
From lib/ohm.rb
113 module Collection
114 include Enumerable
115
116 def each
117 if block_given?
118 ids.each_slice(1000) do |slice|
119 fetch(slice).each { |e| yield(e) }
120 end
121 else
122 to_enum
123 end
124 end
I can't reproduce it either, can you let me know as soon as you find something? If it's a bug with Ohm or Redis, we definitely need to fix it. Can you show a bit more how you are combining everything?
I've updated to do a to_a
and then iterate and see if that helps. I never expect more the 4 children so i'm not buying anything by the each_slice.
x.children.to_a.map {|c| ... }
didn't help...
NoMethodError: undefined method
each' for "214240":String`
where would i find ids
being passed/generated? The ids i pointed to earlier was for list type. I'm not seeing in the source for the meta type collection how ids is compiled.
It's the one defined in Ohm::BasicSet
, check it here.
thanks, just saw that. Long day.
so i have gotten around it at the moment by monkey patching the ids method to use redis-rb to call smembers and all seems to be going well now. I'm not happy with this hack, but i need to get this resolved so it is what it is at the moment.
Locally im running a mac on ruby 2.0, ohm 2.0.1 no issues. Production is ubuntu.
also was getting alot of these ArgumentError: odd number of arguments for Hash
. Found this http://stackoverflow.com/questions/18747713/argumenterror-odd-number-of-arguments-for-hash-when-trying-to-connect-to-redis. We are running latest redis libraries, so didn't apply, but maybe redic is having similar connection issues.
Can you tell me more or less how is your setup? I'm very interested in replicating that error.
@barberj Could it be related to this issue? redis/redis-rb#501
Which Ruby version are you running in prod?
ruby 2.0. I ended up rolling my own home grown redis models since could never get ohm to work.
Can you share some piece of code so that I can try to reproduce it?
Closing this as we don't have a way to replicate the issue.