You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BUG REPORT: Transaction Rollback Not Triggered (COMMIT Instead of ROLLBACK)
1. Problem Description
When using activerecord-sqlserver-adapter, transactions are not rolled back as expected when an exception (ActiveRecord::Rollback or standard exceptions) is raised within a transaction block. Instead, the transaction is committed (log shows COMMIT TRANSACTION), leading to data inconsistency.
2. Steps to Reproduce
Execute the following code:
ActiveRecord::Base.transactiondoContract.create!(result)# Assume `result` is validAnotherModel.create!(another_result)# Assume `another_result` is validraiseActiveRecord::Rollback# Or raise "Test error"end
Observe the logs:
TRANSACTION (2.3ms) COMMIT TRANSACTION
=> nil
Check the database tables to confirm that data was committed (not rolled back).
3. Expected Behavior
When an exception is raised inside a transaction block (e.g., ActiveRecord::Rollback or any other exception), the transaction should be rolled back (log shows ROLLBACK TRANSACTION), and no changes should persist in the database.
4. Actual Behavior
The transaction is committed (log shows COMMIT TRANSACTION), and data is persisted in the database despite the exception.
5. Environment Information
Item
Details
activerecord-sqlserver-adapter version
7.0.7
Rails version
7.0.8.6
Ruby version
3.3.3
SQL Server version
2014
Database Configuration
Provide the SQL Server section from config/database.yml :
production:
sqlserver:
adapter: sqlserverdatabase: my_databseusername: userpassword: psword!host: 192.168.28.102port: 1433timeout: 5000options: "XACT_ABORT=true"# Setting or not setting it here has no effect
6. Logs
Provide the full log snippet (redact sensitive info):
[Logs before transaction]
TRANSACTION (1.7ms) BEGIN TRANSACTION
[Database operations]
TRANSACTION (2.3ms) COMMIT TRANSACTION
7. Solutions Already Tried
✅ Replaced manual begin_transaction/commit_transaction with ActiveRecord::Base.transaction.
✅ Raised ActiveRecord::Rollback explicitly.
✅ Added options: "XACT_ABORT=true" to database.yml.
✅ Upgraded activerecord-sqlserver-adapter to the latest version (run bundle update activerecord-sqlserver-adapter).
8. Additional Notes
9. Attachments
10. Request for Help
Please help confirm:
Is this a known issue with activerecord-sqlserver-adapter?
Could this be related to SQL Server's XACT_ABORT configuration or transaction isolation levels?
Is further debugging of the adapter's transaction management logic required?
The text was updated successfully, but these errors were encountered:
I used the same configuration information as my development environment in the test code, but it reported an error and cannot continue execution:
uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger (NameError)
BUG REPORT: Transaction Rollback Not Triggered (COMMIT Instead of ROLLBACK)
1. Problem Description
When using
activerecord-sqlserver-adapter
, transactions are not rolled back as expected when an exception (ActiveRecord::Rollback
or standard exceptions) is raised within a transaction block. Instead, the transaction is committed (log showsCOMMIT TRANSACTION
), leading to data inconsistency.
2. Steps to Reproduce
3. Expected Behavior
ActiveRecord::Rollback
or any other exception), the transaction should be rolled back (log showsROLLBACK TRANSACTION
), and no changes should persist in the database.
4. Actual Behavior
COMMIT TRANSACTION
), and data is persisted in the database despite the exception.
5. Environment Information
7.0.7
7.0.8.6
3.3.3
2014
config/database.yml
:
6. Logs
Provide the full log snippet (redact sensitive info):
7. Solutions Already Tried
begin_transaction
/commit_transaction
withActiveRecord::Base.transaction
.ActiveRecord::Rollback
explicitly.options: "XACT_ABORT=true"
todatabase.yml
.activerecord-sqlserver-adapter
to the latest version (runbundle update activerecord-sqlserver-adapter
).
8. Additional Notes
9. Attachments
10. Request for Help
Please help confirm:
activerecord-sqlserver-adapter
?XACT_ABORT
configuration or transaction isolation levels?
The text was updated successfully, but these errors were encountered: