From 300da734b8abb154218b4f2a2a540d98f32c64ab Mon Sep 17 00:00:00 2001 From: Wanderson Policarpo Date: Wed, 8 Sep 2021 13:39:29 +0100 Subject: [PATCH] Fix appname resolution when outside Rails context The adapter can be used outside a Rails context so TinyTDS appname config should be able to be resolved if a Rails application was not detected. Fix #942. --- CHANGELOG.md | 6 ++++++ lib/active_record/connection_adapters/sqlserver_adapter.rb | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5948c1b12..e09fbd004 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## Unreleased + +#### Fixed + +- [#943](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/943) Fix appname resolution when outside Rails context + ## v6.1.2.0 [Full changelog](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/compare/v6.1.1.0...v6.1.2.0) diff --git a/lib/active_record/connection_adapters/sqlserver_adapter.rb b/lib/active_record/connection_adapters/sqlserver_adapter.rb index 22b420b8c..4ce55cb96 100644 --- a/lib/active_record/connection_adapters/sqlserver_adapter.rb +++ b/lib/active_record/connection_adapters/sqlserver_adapter.rb @@ -119,9 +119,9 @@ def config_appname(config) end def rails_application_name - return nil if Rails.application.nil? - Rails.application.class.name.split("::").first + rescue + nil # Might not be in a Rails context so we fallback to `nil`. end def config_login_timeout(config)