Skip to content

Conversation

@mgrunberg
Copy link
Contributor

This PR fixes the failure:

TestDisconnectedAdapter#test_0001_can't execute statements while disconnected [/usr/local/bundle/bundler/gems/rails-8b63ea762239/activerecord/test/cases/disconnected_test.rb:25]:
[ActiveRecord::ConnectionNotEstablished] exception expected, not
Class: <ActiveRecord::StatementInvalid>
Message: <"NoMethodError: undefined method `execute' for nil:NilClass\nDid you mean?  expects">

Rails 6.1 expects that we raise an instance of ActiveRecord::ConnectionNotEstablished (see https://github.com/rails/rails/blob/v6.1.0/activerecord/test/cases/disconnected_test.rb).
Rails 6.0 was expecting ActiveRecord::StatementInvalid. In fact, 6-0-stable raises that exception with the message:

"NoMethodError: undefined method `execute' for nil:NilClass\nDid you mean?  expects" 

I use the fact that @connnection is nil to detect when to raise the exception.

…d-refactor

Refactor 'Raise ActiveRecord::ConnectionNotEstablished on calls to execute with a disconnected connection'
@mgrunberg mgrunberg force-pushed the issues/yellowspot/rails-6-1/raise-connection-not-established branch from fd30c0d to 6b73a4e Compare April 27, 2021 15:58
@wpolicarpo wpolicarpo merged commit dac40d7 into rails-sqlserver:main Apr 28, 2021
@mgrunberg mgrunberg deleted the issues/yellowspot/rails-6-1/raise-connection-not-established branch January 3, 2022 17:31
lavika pushed a commit to lavika/activerecord-sqlserver-adapter that referenced this pull request Sep 26, 2023
… execute with a disconnected connection. (rails-sqlserver#903)

* raise ActiveRecord::ConnectionNotEstablished instead of ActiveRecord::StatementInvalid when call execute and connection is disconnected

* add test of other calls to connection.execute that should fail

* add changelog item

* Refactor

* fix typo

* check connection active to prevent usage of dead/closed connection

* raise TinyTds::Error and translate it. 'active?' method is rescuing just those

* Revert "check connection active to prevent usage of dead/closed connection"

This reverts commit 6861763.

* check TinyTds FalseClass response in execute_procedure and raw_connection_run

* raise ConnectionNotEstabilished when TinyTDS returns false

Co-authored-by: Aidan Haran <[email protected]>
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 this pull request may close these issues.

4 participants