Skip to content

Undefined Method Error Caused By Active? #707

Closed
@bendangelo

Description

@bendangelo

Using version 5.1.6, activerecord 5.1.7

I tracked down the error to these lines. Starting from here:

def active?
        return false unless @connection
        raw_connection_do 'SELECT 1'
        true
      rescue *connection_errors
        false
      end

Raw connection is then called:

def raw_connection_do(sql)
          case @connection_options[:mode]
          when :dblib
            @connection.execute(sql).do
          end
        ensure
          @update_sql = false
        end

I believe the error is caused because @connection.execute(sql) can potentially return false. This causes the undefined method do for false class error. But I have not confirmed it.

Stacktrace:

NoMethodError: undefined method `do' for false:FalseClass
/usr/local/bundle/gems/activerecord-sqlserver-adapter-5.1.6/lib/active_record/connection_adapters/sqlserver/database_statements.rb:284:in `raw_connection_do'
/usr/local/bundle/gems/activerecord-sqlserver-adapter-5.1.6/lib/active_record/connection_adapters/sqlserver_adapter.rb:155:in `active?'
/usr/local/bundle/gems/activerecord-5.1.7/lib/active_record/connection_adapters/abstract_adapter.rb:444:in `verify!'
/usr/local/bundle/gems/activerecord-5.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:810:in `block in checkout_and_verify'
/usr/local/bundle/gems/activesupport-5.1.7/lib/active_support/callbacks.rb:131:in `run_callbacks'
/usr/local/bundle/gems/activesupport-5.1.7/lib/active_support/callbacks.rb:827:in `_run_checkout_callbacks'
/usr/local/bundle/gems/activerecord-5.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:809:in `checkout_and_verify'
/usr/local/bundle/gems/activerecord-5.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:502:in `checkout'
/usr/local/bundle/gems/activerecord-5.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:376:in `connection'
/usr/local/bundle/gems/activerecord-5.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:933:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-5.1.7/lib/active_record/connection_handling.rb:116:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-5.1.7/lib/active_record/connection_handling.rb:88:in `connection'
/usr/local/bundle/gems/activerecord-5.1.7/lib/active_record/core.rb:301:in `cached_find_by_statement'
/usr/local/bundle/gems/activerecord-5.1.7/lib/active_record/core.rb:183:in `find'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions