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

TypeError when calling all/last/first/select on paranoid model with abstract parent class. #310

Open
Derenge opened this issue Feb 8, 2016 · 3 comments

Comments

@Derenge
Copy link

Derenge commented Feb 8, 2016

When calling any scoped action on a model that inherits act_as_paranoid from an abstract class postgresql has a type error. "TypeError: no implicit conversion of nil into String"

This can be avoided by putting act_as_paranoid on the child class.

class Parent < ActiveRecord::Base
  acts_as_paranoid
  self.abstract_class = true
end

class Child < Parent
end

migration

class CreateChildren < ActiveRecord::Migration
  def change
    create_table :children do |t|
      t.datetime :deleted_at
    end
  end
end

Steps to reproduce:
Call Child.all

Stack trace

TypeError: no implicit conversion of nil into String
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql/utils.rb:24:in`quote_ident'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql/utils.rb:24:in `quoted'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql/quoting.rb:31:in`quote_table_name'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/arel-6.0.3/lib/arel/visitors/to_sql.rb:776:in `quote_table_name'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/arel-6.0.3/lib/arel/visitors/to_sql.rb:711:in`visit_Arel_Attributes_Attribute'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/arel-6.0.3/lib/arel/visitors/reduce.rb:13:in `visit'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/arel-6.0.3/lib/arel/visitors/to_sql.rb:675:in`visit_Arel_Nodes_Equality'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/arel-6.0.3/lib/arel/visitors/reduce.rb:13:in `visit'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/arel-6.0.3/lib/arel/visitors/to_sql.rb:794:in`block in inject_join'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/arel-6.0.3/lib/arel/visitors/to_sql.rb:792:in `each'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/arel-6.0.3/lib/arel/visitors/to_sql.rb:792:in`each_with_index'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/arel-6.0.3/lib/arel/visitors/to_sql.rb:792:in `each'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/arel-6.0.3/lib/arel/visitors/to_sql.rb:792:in`inject'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/arel-6.0.3/lib/arel/visitors/to_sql.rb:792:in `inject_join'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/arel-6.0.3/lib/arel/visitors/to_sql.rb:650:in`visit_Arel_Nodes_And'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/arel-6.0.3/lib/arel/visitors/reduce.rb:13:in `visit'
... 9 levels...
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/arel-6.0.3/lib/arel/visitors/reduce.rb:7:in`accept'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/database_statements.rb:12:in `to_sql'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/database_statements.rb:32:in`select_all'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/query_cache.rb:70:in `select_all'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/querying.rb:39:in`find_by_sql'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/relation.rb:639:in `exec_queries'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/relation.rb:515:in`load'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/relation.rb:243:in `to_a'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.1/lib/active_record/relation.rb:630:in`inspect'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5.1/lib/rails/commands/console.rb:110:in `start'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5.1/lib/rails/commands/console.rb:9:in`start'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5.1/lib/rails/commands/commands_tasks.rb:68:in `console'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5.1/lib/rails/commands/commands_tasks.rb:39:in`run_command!'
        from /Users/derenge/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5.1/lib/rails/commands.rb:17:in `<top (required)>'
        from bin/rails:4:in`require'
        from bin/rails:4:in `<main>'irb(main):007:0>
@BenMorganIO
Copy link
Collaborator

From the stack trace, I don't see Paranoia ever getting called. Could you provide the full backtrace?

@phoet
Copy link

phoet commented Apr 24, 2019

i just ran into this.

we have acts_as_paranoid on our abstract ApplicationRecord which seems to work fine for all other cases.

when trying to recover, the arel visitor is not able to pick up the names of the relations causing this error.

this is from my current debugging session:

 727:       def visit_Arel_Attributes_Attribute o, collector
   728:         join_name = o.relation.table_alias || o.relation.name
=> 729:         collector << "#{quote_table_name join_name}.#{quote_column_name o.name}"
   730:       end
   731:       alias :visit_Arel_Attributes_Integer :visit_Arel_Attributes_Attribute
   732:       alias :visit_Arel_Attributes_Float :visit_Arel_Attributes_Attribute
   733:       alias :visit_Arel_Attributes_Decimal :visit_Arel_Attributes_Attribute
(byebug) join_name = o.relation.table_alias || o.relation.name
""
(byebug) o.name
"deleted_at"
(byebug) o.relation
#<Arel::Table:0x00007fa9a9bc0430 @name="", @type_caster=#<ActiveRecord::TypeCaster::Connection:0x00007fa9a9bc0480 @klass=StaffMember(...), @table_name="">, @table_alias=nil>

@conroywhitney
Copy link

Did anyone figure out a solution to this for Rails 4 other than putting acts_as_paranoid on the Child class? I know I've had this pattern work in Rails 5...

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

4 participants