soveran/ohm

Connection Pooling Failing on Sets

Closed this issue · 12 comments

Two previous issues (#170 and #89 ) say using redic-pool (https://github.com/djanowski/redic-pool) with ohm 2.0 works well, but it doesn't seem to be working at all for me. It looks like its failing on sets.

A simple test demonstrates the issue:

describe LiveDomain do

  describe 'works with enumerable' do
    it 'yields an instance with an id' do
        LiveDomain.create(domain: 'domain1')
        LiveDomain.create(domain: 'domain2')
        LiveDomain.all.each_with_index do |live_domain, i|
            expect(live_domain.id.to_i).to eq i+1
        end
    end
  end
end

This passes as you would expect without redic-pool, with redic-pool though it raises an error:

Failure/Error: LiveDomain.all.each_with_index do |live_domain, i|
NoMethodError:
   undefined method 'url=' for #<LiveDomain:0x007fe12ee2f038 @attributes={}, @_memo={}>
 # ./spec/ohm_models/live_domain_spec.rb:17:in 'each_with_index'
 # ./spec/ohm_models/live_domain_spec.rb:17:in 'block (3 levels) in <top (required)>'
 # -e:1:in '<main>'

Is this a flaw in Ohm, or redic-pool? Or am I using it wrong perhaps?

Any insight would be appreciated,
Josh

Can you paste the definition of LiveDomain?

Yeah, here's the short version:

 class LiveDomain < Ohm::Model

attribute :domain
unique :domain
collection :pages, :Page
end

the url attribute - the undefined element from the test - is defined in the the Page class, so presumably the redic connections are getting crossed somehow. Actually I just realized on my Page tests the element that's failing is domain, so the two are clearly getting crossed somehow:

undefined method 'domain=' for #<Page:0x007fe12ef07e10 @attributes={}, @_memo={}>

class Page < Ohm::Model

attribute :url
attribute :path
attribute :page_depth
reference :live_domain, :LiveDomain
end

Summoning @djanowski to check the redic-pool part.

Hi! Is there any news on this? I ran across the exact same issue today. Without using connection pooling everything works as expected, as soon as Ohm.redis is changed over to a Redic::Pool instance I get the same kind of errors @kosh-jelly is experiencing.

I've stumbled across this as well.

Looking at it.

To be more precise, I'm getting a different error. The Ohm::Set seems to be trying to make a Hash with an argument of unexpected type.

It happens here for me: https://github.com/soveran/ohm/blob/master/lib/ohm.rb#L75 where arr == "OK".

This should be fixed in redic-pool 1.0.1. Can you please give it a try?

My issue seems fixed. I don't know about @kosh-jelly's though!

I think we can close this!

I just tested it on my end, and redic-pool 1.0.1 definitely solves it. Thank you!

Thanks!