Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8718 (closed defect: duplicate)

Opened 1 year ago

Last modified 1 year ago

[PATCH] SqlServer adapter can prematurely commit a transaction

Reported by: benhell Assigned to: tomafro
Priority: normal Milestone: 1.x
Component: ActiveRecord Version: 1.2.3
Severity: normal Keywords: sqlserver transaction commit autocommit
Cc:

Description

When the indexes method is called on the sqlserver adapter, at the end of the method, AutoCommit is forced to true. If you're in a transaction at the time, this causes the adapter to commit the transaction, ending it prematurely. Rails doesn't realize it, though, and the subsequent call to rollback doesn't throw an error.

This shows up particularly clearly with transactional fixtures in testing if you're using the Redhill on Rails Core plugin. At the beginning of the test, the Redhill plugin calls the indexes method, effectively killing the transaction. At the end of the test, teardown rolls back the transaction to restore the test database to a pristine state, but your changes during the test do not rollback because the transaction's already long gone. As a result, subsequent tests have dirty data.

I don't know how frequently the indexes method gets called. I suspect that in production it happens on boot only. However, I could see data integrity issues popping up.

Caching the current AutoCommit at the beginning of the method and restoring it to the cached value at the end appears to alleviate this problem, at least for my machine.

This is related to #8107.

Attachments

sqlserver_preserve_autocommit_value_when_getting_indexes.diff (1.9 kB) - added by tomafro on 07/03/07 16:14:39.

Change History

07/03/07 14:50:27 changed by tomafro

  • owner changed from core to tomafro.

Awesome discovery. I think I've encountered this nastiness.

07/03/07 14:50:46 changed by tomafro

  • keywords set to sqlserver transaction commit autocommit.

07/03/07 16:14:39 changed by tomafro

  • attachment sqlserver_preserve_autocommit_value_when_getting_indexes.diff added.

07/03/07 16:18:38 changed by tomafro

  • summary changed from SqlServer adapter can prematurely commit a transaction to [PATCH] SqlServer adapter can prematurely commit a transaction.

Added patch to preserve the autocommit value, rather than suddenly ending the transaction.

07/03/07 17:48:10 changed by tomafro

  • status changed from new to closed.
  • resolution set to duplicate.

Rolled up into #8862