{"action":"opened","issue":{"url":"https://api.github.com/repos/rails-sqlserver/activerecord-sqlserver-adapter/issues/466","repository_url":"https://api.github.com/repos/rails-sqlserver/activerecord-sqlserver-adapter","labels_url":"https://api.github.com/repos/rails-sqlserver/activerecord-sqlserver-adapter/issues/466/labels{/name}","comments_url":"https://api.github.com/repos/rails-sqlserver/activerecord-sqlserver-adapter/issues/466/comments","events_url":"https://api.github.com/repos/rails-sqlserver/activerecord-sqlserver-adapter/issues/466/events","html_url":"https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues/466","id":150039665,"number":466,"title":"exec_rollback_db_transaction raises error when SQL-Query creates error","user":{"login":"RobWu","id":237810,"avatar_url":"https://avatars.githubusercontent.com/u/237810?v=3","gravatar_id":"","url":"https://api.github.com/users/RobWu","html_url":"https://github.com/RobWu","followers_url":"https://api.github.com/users/RobWu/followers","following_url":"https://api.github.com/users/RobWu/following{/other_user}","gists_url":"https://api.github.com/users/RobWu/gists{/gist_id}","starred_url":"https://api.github.com/users/RobWu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RobWu/subscriptions","organizations_url":"https://api.github.com/users/RobWu/orgs","repos_url":"https://api.github.com/users/RobWu/repos","events_url":"https://api.github.com/users/RobWu/events{/privacy}","received_events_url":"https://api.github.com/users/RobWu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-04-21T11:03:31Z","updated_at":"2016-04-21T11:03:31Z","closed_at":null,"body":"https://github.com/rails-sqlserver/tiny_tds/issues/267\r\n\r\nI try to create a new barcode.\r\n\r\n```ruby\r\nBarcode.create!(member_shiporder_line_id: 904577)\r\n```\r\nThis executes:\r\n```ruby\r\n@connection.execute(BEGIN TRANSACTION).do\r\n  SQL (6.5ms)  BEGIN TRANSACTION\r\n  SQL (9.1ms)  EXEC sp_executesql N'INSERT INTO [barcode] ([membershiporderlineid]) OUTPUT INSERTED.[id] VALUES (@0)', N'@0 int', @0 = 904577  [[\"membershiporderlineid\", 904577]]\r\n\r\nMY ADDED DEBUG INFO : # PUTS inside gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/transaction.rb:187:in `rescue in within_new_transaction'\r\n - #<ActiveRecord::StatementInvalid: TinyTds::Error: Cannot insert the value NULL into column 'barcode_postfix', table 'prod_2015_bio_membership_rhg_dev.dbo.Barcode'; column does not allow nulls. INSERT fails.: EXEC sp_executesql N'INSERT INTO [barcode] ([membershiporderlineid]) OUTPUT INSERTED.[id] VALUES (@0)', N'@0 int', @0 = 904577>\r\n\r\n@connection.execute(IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION).do\r\n  SQL (8.0ms)  IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION\r\n\r\nActiveRecord::StatementInvalid: TinyTds::Error: The request failed to run because the batch is aborted, this can be caused by abort signal sent from client, or another request is running in the same session, which makes the session busy.: IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION\r\n\tfrom /Users/row/.rvm/gems/ruby-2.3.0@biografklub/gems/activerecord-sqlserver-adapter-4.2.10/lib/active_record/connection_adapters/sqlserver/database_statements.rb:302:in `do'\r\n\tfrom /Users/row/.rvm/gems/ruby-2.3.0@biografklub/gems/activerecord-sqlserver-adapter-4.2.10/lib/active_record/connection_adapters/sqlserver/database_statements.rb:302:in `raw_connection_do'\r\n\tfrom /Users/row/.rvm/gems/ruby-2.3.0@biografklub/gems/activerecord-sqlserver-adapter-4.2.10/lib/active_record/connection_adapters/sqlserver/database_statements.rb:254:in `block in do_execute'\r\n\tfrom /Users/row/.rvm/gems/ruby-2.3.0@biografklub/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:472:in `block in log'\r\n\tfrom /Users/row/.rvm/gems/ruby-2.3.0@biografklub/gems/activesupport-4.2.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'\r\n\tfrom /Users/row/.rvm/gems/ruby-2.3.0@biografklub/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:466:in `log'\r\n\tfrom /Users/row/.rvm/gems/ruby-2.3.0@biografklub/gems/activerecord-sqlserver-adapter-4.2.10/lib/active_record/connection_adapters/sqlserver/database_statements.rb:254:in `do_execute'\r\n\tfrom /Users/row/.rvm/gems/ruby-2.3.0@biografklub/gems/activerecord-sqlserver-adapter-4.2.10/lib/active_record/connection_adapters/sqlserver/database_statements.rb:69:in `exec_rollback_db_transaction'\r\n\tfrom /Users/row/.rvm/gems/ruby-2.3.0@biografklub/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:266:in `rollback_db_transaction'\r\n\tfrom /Users/row/.rvm/gems/ruby-2.3.0@biografklub/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `rollback_db_transaction'\r\n\tfrom /Users/row/.rvm/gems/ruby-2.3.0@biografklub/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/transaction.rb:145:in `rollback'\r\n\tfrom /Users/row/.rvm/gems/ruby-2.3.0@biografklub/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/transaction.rb:179:in `rollback_transaction'\r\n\tfrom /Users/row/.rvm/gems/ruby-2.3.0@biografklub/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/transaction.rb:187:in `rescue in within_new_transaction'\r\n\tfrom /Users/row/.rvm/gems/ruby-2.3.0@biografklub/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/transaction.rb:202:in `within_new_transaction'\r\n\tfrom /Users/row/.rvm/gems/ruby-2.3.0@biografklub/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'\r\n\tfrom /Users/row/.rvm/gems/ruby-2.3.0@biografklub/gems/activerecord-4.2.6/lib/active_record/transactions.rb:220:in `transaction'\r\n\tfrom /Users/row/.rvm/gems/ruby-2.3.0@biografklub/gems/activerecord-4.2.6/lib/active_record/transactions.rb:348:in `with_transaction_returning_status'\r\n\tfrom /Users/row/.rvm/gems/ruby-2.3.0@biografklub/gems/activerecord-4.2.6/lib/active_record/transactions.rb:291:in `save!'\r\n\tfrom /Users/row/.rvm/gems/ruby-2.3.0@biografklub/gems/activerecord-4.2.6/lib/active_record/persistence.rb:51:in `create!'\r\n\tfrom (irb):7\r\n\tfrom /Users/row/.rvm/gems/ruby-2.3.0@biografklub/gems/railties-4.2.6/lib/rails/commands/console.rb:110:in `start'\r\n\tfrom /Users/row/.rvm/gems/ruby-2.3.0@biografklub/gems/railties-4.2.6/lib/rails/commands/console.rb:9:in `start'\r\n\tfrom /Users/row/.rvm/gems/ruby-2.3.0@biografklub/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:68:in `console'\r\n\tfrom /Users/row/.rvm/gems/ruby-2.3.0@biografklub/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!'\r\n\tfrom /Users/row/.rvm/gems/ruby-2.3.0@biografklub/gems/railties-4.2.6/lib/rails/commands.rb:17:in `<top (required)>'\r\n\tfrom bin/rails:9:in `require'\r\n\tfrom bin/rails:9:in `<main>'2.3.0 :008 > exit\r\n```\r\n\r\nLooks like there is an exceptions for the ```create!``` call.. \r\n```\r\nDEBUG INFO : # PUTS inside gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/transaction.rb:187:in `rescue in within_new_transaction'\r\n\r\n - #<ActiveRecord::StatementInvalid: TinyTds::Error: Cannot insert the value NULL into column 'barcode_postfix', table 'prod_2015_bio_membership_rhg_dev.dbo.Barcode'; column does not allow nulls. INSERT fails.: EXEC sp_executesql N'INSERT INTO [barcode] ([membershiporderlineid]) OUTPUT INSERTED.[id] VALUES (@0)', N'@0 int', @0 = 904577>\r\n```\r\n\r\nBecause of this exception, ```exec_rollback_db_transaction``` will be executed, and created a new and different error (```The request failed to run because the batch is aborted...```), and hides the original error (```Cannot insert the value NULL into column```) at the same time.."}}