Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finding non-existent record in assocation causes Cannot visit UUIDTools::UUID with Rails 3 #69

Open
zben opened this issue Jun 8, 2015 · 0 comments

Comments

@zben
Copy link

zben commented Jun 8, 2015

With Rails 3.2.17, If parent model and children model are both uuid model.

Child.where(parent_id: xxx).find(SecureRandom.hex) 

gives correct RecordNotFound error

However,

parent.children.find(SecureRandom.hex) 

gives TypeError.

I had to fix it with a monkey-patch

module Arel
  class SelectManager < Arel::TreeManager
    def where_sql
      return if @ctx.wheres.empty?

      viz = Visitors::WhereSql.new @engine.connection
      Nodes::SqlLiteral.new viz.accept @ctx
    rescue TypeError => e
      nil
    end
  end
end

This works but is not clean. I also see that this issue does not apply to Rails 4. I tried to submit a PR for activeuuid but I realize it is using activerecord v4 in the spec. What is the guideline on this type of error. Will you guys try to have your code compatible with Rails 3.2.x?

backtrace

 Failure/Error: specify { parent.uuid_articles.find(SecureRandom.hex.to_s).should == article }
     TypeError:
       Cannot visit UUIDTools::UUID
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/arel-3.0.3/lib/arel/visitors/visitor.rb:25:in `rescue in visit'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/arel-3.0.3/lib/arel/visitors/visitor.rb:19:in `visit'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/arel-3.0.3/lib/arel/visitors/to_sql.rb:407:in `visit_Arel_Nodes_Equality'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/arel-3.0.3/lib/arel/visitors/visitor.rb:19:in `visit'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/arel-3.0.3/lib/arel/visitors/to_sql.rb:389:in `block in visit_Arel_Nodes_And'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/arel-3.0.3/lib/arel/visitors/to_sql.rb:389:in `map'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/arel-3.0.3/lib/arel/visitors/to_sql.rb:389:in `visit_Arel_Nodes_And'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/arel-3.0.3/lib/arel/visitors/visitor.rb:19:in `visit'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/arel-3.0.3/lib/arel/visitors/where_sql.rb:5:in `block in visit_Arel_Nodes_SelectCore'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/arel-3.0.3/lib/arel/visitors/where_sql.rb:5:in `map'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/arel-3.0.3/lib/arel/visitors/where_sql.rb:5:in `visit_Arel_Nodes_SelectCore'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/arel-3.0.3/lib/arel/visitors/visitor.rb:19:in `visit'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/arel-3.0.3/lib/arel/visitors/visitor.rb:5:in `accept'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/arel-3.0.3/lib/arel/visitors/to_sql.rb:19:in `accept'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/arel-3.0.3/lib/arel/select_manager.rb:177:in `where_sql'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/activerecord-3.2.17/lib/active_record/relation/finder_methods.rb:342:in `find_one'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/activerecord-3.2.17/lib/active_record/relation/finder_methods.rb:315:in `find_with_ids'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/activerecord-3.2.17/lib/active_record/relation/finder_methods.rb:107:in `find'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/activerecord-3.2.17/lib/active_record/associations/collection_association.rb:95:in `find'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/activerecord-3.2.17/lib/active_record/associations/collection_proxy.rb:46:in `find'
     # ./spec/lib/activerecord_spec.rb:147:in `block (4 levels) in <top (required)>'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/rspec-core-2.99.2/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_exec'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/rspec-core-2.99.2/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_eval_with_args'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/rspec-core-2.99.2/lib/rspec/core/example.rb:116:in `block in run'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/rspec-core-2.99.2/lib/rspec/core/example.rb:248:in `with_around_each_hooks'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/rspec-core-2.99.2/lib/rspec/core/example.rb:113:in `run'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:515:in `block in run_examples'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:511:in `map'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:511:in `run_examples'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:496:in `run'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:497:in `block in run'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:497:in `map'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:497:in `run'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:497:in `block in run'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:497:in `map'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/rspec-core-2.99.2/lib/rspec/core/example_group.rb:497:in `run'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/rspec-core-2.99.2/lib/rspec/core/command_line.rb:24:in `block (2 levels) in run'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/rspec-core-2.99.2/lib/rspec/core/command_line.rb:24:in `map'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/rspec-core-2.99.2/lib/rspec/core/command_line.rb:24:in `block in run'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/rspec-core-2.99.2/lib/rspec/core/reporter.rb:58:in `report'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/rspec-core-2.99.2/lib/rspec/core/command_line.rb:21:in `run'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:103:in `run'
     # /Users/ben/.rvm/gems/ruby-1.9.3-p551/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:17:in `block in autorun'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant