Skip to content

ActiveRecord::Base.send(:sanitize_sql, ...) in Rails 2.3.8 #10

@smlsml

Description

@smlsml

In versions beyond 2.3.2 (not sure exactly which one - definitely by 2.3.8) sanitize_sql expects to be operating on a subclass of ActiveRecord::Base. The attempt to call the method directly on ActiveRecord::Base causes:

undefined method abstract_class?' for Object:Class gems/activerecord-2.3.8/lib/active_record/base.rb:2242:inclass_of_active_record_descendant'
gems/activerecord-2.3.8/lib/active_record/base.rb:1492:in base_class' gems/activerecord-2.3.8/lib/active_record/base.rb:1164:inreset_table_name'
gems/activerecord-2.3.8/lib/active_record/base.rb:1160:in table_name' gems/activerecord-2.3.8/lib/active_record/base.rb:3154:inquoted_table_name'
gems/ar-extensions-0.9.2/lib/ar-extensions/finders.rb:22:in `sanitize_sql'
...

This comes from:

  • lib/desert/plugin_migrations/2.1/extensions/schema_statements.rb:23
    insert_sql = ActiveRecord::Base.send(:sanitize_sql, [...

This is a case where calling a non-public method using .send eventually comes back to bite you. The query in question only has two values - using the connection adapter (connection.quote()) to quote the values directly would be the better solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions