diff options
author | Keenan Brock <keenan@thebrocks.net> | 2017-03-09 11:48:44 -0500 |
---|---|---|
committer | Keenan Brock <keenan@thebrocks.net> | 2017-11-06 13:59:03 -0500 |
commit | 01c703248396528d9f3398d0f9d0143831e9d0dc (patch) | |
tree | d197f58651d504874ef04ac04b92a4a275c04780 /activerecord | |
parent | 204b22fa1c739e07d8487ace5710f8f2abe27c0e (diff) | |
download | rails-01c703248396528d9f3398d0f9d0143831e9d0dc.tar.gz rails-01c703248396528d9f3398d0f9d0143831e9d0dc.tar.bz2 rails-01c703248396528d9f3398d0f9d0143831e9d0dc.zip |
Properly check transaction in persistence
```
[NoMethodError]: undefined method `state' for nil:NilClass Method:[rescue in block in refresh]
```
In `within_new_transaction`, there is the possibility that
`begin_transaction` returns a `nil`. (i.e.: so `transaction = nil`)
So this method is checking `transaction` for nil in 2 spots.
Unfortunately, there is one line that is not checking `transaction` for `nil`
That line, `commit_transaction`, throws an exception for us in AR 5.0.0.1
The problem with the method is finally realized in the error checking itself.
it calls `transaction.state` (i.e.: nil.state) and that is the final exception
raised.
The actual underlying (user) issue is hidden by this line.
Solution is test transaction for nil.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/transaction.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb b/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb index 147e16e9fa..d9ac8db6a8 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb @@ -240,7 +240,7 @@ module ActiveRecord rollback_transaction if transaction else begin - commit_transaction + commit_transaction if transaction rescue Exception rollback_transaction(transaction) unless transaction.state.completed? raise |