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

Undefined Method Error Caused By Active? #707

Closed
bendangelo opened this issue Sep 18, 2019 · 3 comments
Closed

Undefined Method Error Caused By Active? #707

bendangelo opened this issue Sep 18, 2019 · 3 comments

Comments

@bendangelo
Copy link

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'
Svelix pushed a commit to Svelix/activerecord-sqlserver-adapter that referenced this issue Dec 17, 2019
The tiny_tds lib might return false on execute when the call fails.
This caused exceptions when active? is called after the connection
was lost.

fixes rails-sqlserver#707
@wpolicarpo
Copy link
Member

Closing this via #818, #825 and rails-sqlserver/tiny_tds/pull/469.

@taylorthurlow
Copy link

taylorthurlow commented Aug 13, 2020

@wpolicarpo Is there any chance of getting the two PRs you linked above backported to 5.x?

EDIT: So it seems that the 5-2-stable branch contains the fix, but there is no 5.2.x release which contains that change yet (current status of line in 5.2.1).

@wpolicarpo
Copy link
Member

@taylorthurlow I backported it already. Problem is that 5-2-stable is currently broken and I don't want to cut a release without fixing the specs first. I will see if I have some time during the weekend to look into that.

aquarhead added a commit to PLAIO/activerecord-sqlserver-adapter that referenced this issue Jan 7, 2025
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

Successfully merging a pull request may close this issue.

3 participants