aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/transactions.rb
Commit message (Collapse)AuthorAgeFilesLines
* Avoid using heredoc for user warningsGodfrey Chan2014-08-281-10/+9
| | | | | | | | | | Using heredoc would enforce line wrapping to whatever column width we decided to use in the code, making it difficult for the users to read on some consoles. This does make the source code read slightly worse and a bit more error-prone, but this seems like a fair price to pay since the primary purpose for these messages are for the users to read and the code will not stick around for too long.
* make it easy to copy & paste the config from deprecation warning.Yves Senn2014-08-281-2/+3
| | | | [ci skip]
* Fix after_commit warning messageArthur Neves2014-08-181-1/+1
|
* Add option to stop swallowing errors on callbacks.Arthur Neves2014-08-181-4/+22
| | | | | | | | | | | | | | | Currently, Active Record will rescue any errors raised within after_rollback/after_create callbacks and print them to the logs. Next versions of rails will not rescue those errors anymore, and just bubble them up, as the other callbacks. This adds a opt-in flag to enable that behaviour, of not rescuing the errors. Example: # For not swallow errors in after_commit/after_rollback config.active_record.errors_in_transactional_callbacks = true [fixes #13460]
* Merge pull request #15564 from sgrif/sg-remove-dead-codeRafael Mendonça França2014-06-071-7/+2
|\ | | | | | | | | | | | | Remove dead branch when restoring ID within a transaction Conflicts: activerecord/lib/active_record/transactions.rb
| * Remove dead branch when restoring ID within a transactionSean Griffin2014-06-071-7/+2
| | | | | | | | | | | | | | There is no way to have an instance of an Active Record model where `has_attribute?(self.class.primary_key)` returns false. The record is always initialized in such a way that `@raw_attributes` will have an id key with nil for the value.
* | Move conditionals about freezing closer to the definition of `freeze`Sean Griffin2014-06-071-4/+2
|/ | | | | | | Reduces the number of places that care about the internals of how we store and type cast attributes. We do not need to go through the dup/freeze dance, as you couldn't have saved a frozen new record anyway, and that is the only time we would end up modifying the frozen hash.
* Rename attribute related instance variables to better express intentSean Griffin2014-05-301-4/+4
| | | | | | | | | `@attributes` was actually used for `_before_type_cast` and friends, while `@attributes_cache` is the type cast version (and caching is the wrong word there, but I'm working on removing the conditionals around that). I opted for `@raw_attributes`, because `_before_type_cast` is also semantically misleading. The values in said hash are in the state given by the form builder or database, so raw seemed to be a good word.
* fix typo [ci skip]Vijay Dev2014-05-171-1/+1
|
* Remove unecessary requireArthur Neves2014-05-161-2/+0
|
* Reuse the force_clear_transaction_record_stateRafael Mendonça França2014-05-161-1/+1
|
* Missed if :bomb:Rafael Mendonça França2014-05-161-1/+1
|
* Add a specific method to force the transaction record state clearRafael Mendonça França2014-05-161-5/+8
| | | | | | We are using that code path in only one place so we should not add a conditional to all the other cases. This will avoid performance regressions on the old paths.
* Clear transaction state if callback raise rollbackArthur Neves2014-05-151-1/+1
|
* Small refactoring on clear_transaction_record_stateArthur Neves2014-05-151-3/+5
| | | | | | Make sure when we clean the `@_start_transaction_state` var we do it in the same code-path. Also this makes `clear_transaction_record_state`, more consistent with `restore_transaction_record_state`
* Reverts "Fix bugs with changed attributes tracking when transaction gets ↵Arthur Neves2014-05-091-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | rollback" We are reverting these commits, because there are other caveats related to dirty attributes not being restored when a transaction is rollback. For instance, nested transactions cannot proper restore the dirty attributes state after a rollback. At the moment, the dirty attributes are scoped by the transaction. When we call `.save` on a record, the dirty attributes will be reset even if the transaction gets rollback. [related #13166] [related #15018] [related #15016] [closes #15019] This reverts commits * bab48f0a3d53a08bc23ea0887219e8deb963c3d9 * b0fa7cf3ff8432cc2eef3682b34763b7f8c93cc8. * 73fb39b6faa9de593ae75ad4e3b8e065ea0e53af * 37c238927fbed059de3f26a90d8923fb377568a5. * 8d8d4f1560264cd1c74364d67fa0501f6dd2c4fa Revert "Merge pull request #13166 from bogdan/transaction-magic"
* Dup the changed_attributes otherwise we could lose themArthur Neves2014-05-071-1/+1
|
* Keep track of dirty attrs after after rollback.Arthur Neves2014-05-071-2/+0
| | | | [related #13166]
* Merge pull request #13166 from bogdan/transaction-magicRafael Mendonça França2014-05-071-0/+6
|\ | | | | | | [Regression 3.2 -> 4.0] Fix bugs with changed attributes tracking when transaction gets rollback
| * Fix bugs with changed attributes tracking when transaction gets rollbackBogdan Gusiev2013-12-041-0/+6
| |
* | AR .persisted? throws SystemStackError for an unsaved model with achrisfinne2014-03-271-1/+1
| | | | | | | | custom primary_key that didn't save due to validation error
* | Make sure transaction state resets after commitArthur Neves2014-02-031-1/+1
| | | | | | | | [fixes #12566]
* | Make AR::Base#touch fire the after_commit and after_rollback callbacksHarry Brundage2014-01-161-0/+4
| |
* | Get rid of unused TransactionError constantCarlos Antonio da Silva2014-01-151-3/+0
| | | | | | | | | | | | This has been added 9 years ago in a677da209b16f43198b3485dda89dce862fb9bfb, and removed 6 years ago in 38f8252e2d0a109d1b833d6b289cd989e7bfffe4.
* | Avoid converting :on option to array twice when defining commit/rollback ↵Carlos Antonio da Silva2014-01-151-3/+2
|/ | | | callbacks
* Fixed typo with after_commit docsChris Ledet2013-10-251-2/+2
| | | Fixed syntax error on `after_commit` docs
* #4566: Remove extra decrement of transaction levelPaul Nikitochkin2013-07-141-3/+3
| | | | | | | | | | | | `rollback_active_record_state!` tries to restore model state on `Exception` by invoking `restore_transaction_record_state` it decrement deep level by `1`. After restoring it ensure that states to be cleared and level decremented by invoking `clear_transaction_record_state`, which cause the bug: because state already reduced in `restore_transaction_record_state`. Removed double derement of transaction level and removed duplicated code which clear transaction state for top level.
* removed unnecessary mapping for on optionsAnton Kalyaev2013-06-251-5/+5
| | | | | | | | | Right before that in `assert_valid_transaction_action` method we make sure that `options[:on]` contains values from `ACTIONS` array (`[:create, :destroy, :update]`) and nothing more (i.e. it could not contain strings or something else, otherwise the error is raised). Also I've polished some docs.
* deprecating string based terminatorsAaron Patterson2013-05-141-1/+3
|
* Revert "Merge pull request #6226 from gnufied/master"Rafael Mendonça França2013-04-101-2/+6
| | | | | | | | | | | | | This reverts commit 9bf1a0db4acbbf9e8e6f707250269185224e7efe, reversing changes made to fed97091b9546d369a240d10b184793d49247dd3. Conflicts: activerecord/test/cases/transaction_callbacks_test.rb Reason: This fix introduces another issue described at #8937, so we are reverting it to restore the behavior of 3-2-stable. We will fix both issues when we come out with a better solution
* SQLite3 3.6.8+ supports nested transactions [ci skip]Neeraj Singh2013-03-181-1/+1
| | | | | http://www.sqlite.org/lang_savepoint.html https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb#L130-L132
* multiple actions for :on option with `after_commit` and `after_rollback`Yves Senn2013-02-211-14/+17
| | | | Closes #988.
* Don't call after_commit when creating through an association and save fails, ↵James Miller2013-02-131-1/+4
| | | | fixes #5802
* validate :on option on after_commit and after_rollback callbacksPascal Friederich2012-12-261-6/+16
|
* 1.9 Syntax related changesAvnerCohen2012-11-101-14/+14
|
* frozen state should be restored after txn is abortedAaron Patterson2012-10-221-2/+3
|
* Fix out-of-date URL.Alex Reisner2012-09-191-1/+1
|
* Revert "create a transaction object and point AR objects at that object ↵Jon Leighton2012-09-151-29/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | during a" This reverts commit c24c885209ac2334dc6f798c394a821ee270bec6. Here's the explanation I just sent to @tenderlove: Hey, I've been thinking about about the transaction memory leak thing that we were discussing. Example code: post = nil Post.transaction do N.times { post = Post.create } end Post.transaction is going to create a real transaction and there will also be a (savepoint) transaction inside each Post.create. In an idea world, we'd like all but the last Post instance to be GC'd, and for the last Post instance to receive its after_commit callback when Post.transaction returns. I can't see how this can work using your solution where the Post itself holds a reference to the transaction it is in; when Post.transaction returns, control does not switch to any of Post's instance methods, so it can't trigger the callbacks itself. What we really want is for the transaction itself to hold weak references to the objects within the transaction. So those objects can be GC'd, but if they are not GC'd then the transaction can iterate them and execute their callbacks. I've looked into WeakRef implementations that are available. On 1.9.3, the stdlib weakref library is broken and we shouldn't use it. There is a better implementation here: https://github.com/bdurand/ref/blob/master/lib/ref/weak_reference/pure_ruby.rb We could use that, either by pulling in the gem or just copying the code in, but it still suffers from the limitation that it uses ObjectSpace finalizers. In my testing, this finalizers make GC quite expensive: https://gist.github.com/3722432 Ruby 2.0 will have a native WeakRef implementation (via ObjectSpace::WeakMap), hence won't be reliant on finalizers: http://bugs.ruby-lang.org/issues/4168 So the ultimate solution will be for everyone to use Ruby 2.0, and for us to just use ObjectSpace::WeakMap. In the meantime, we have basically 3 options: The first is to leave it as it is. The second is to use a finalizer-based weakref implementation and take the GC perf hit. The final option is to store object ids rather than the actual objects. Then use ObjectSpace._id2ref to deference the objects at the end of the transaction, if they exist. This won't stop memory use growing within the transaction, but it'll grow more slowly. I benchmarked the performance of _id2ref this if the object does or does not exist: https://gist.github.com/3722550 If it does exist it seems decent, but it's hugely more expensive if it doesn't, probably because we have to do the rescue nil. Probably most of the time the objects will exist. However the point of doing this optimisation is to allow people to create a large number of objects inside a transaction and have them be GC'd. So for that use case, we'd be replacing one problem with another. I'm not sure which of the two problems is worse. My feeling is that we should just leave this for now and come back to it when Ruby 2.0 is out. I'm going to revert your commit because I can't see how it solves this. Hope you don't mind... if I've misunderstood then let me know! Jon
* create a transaction object and point AR objects at that object during aAaron Patterson2012-09-071-6/+29
| | | | transaction.
* documents after_(commit|rollback)Xavier Noria2012-08-301-0/+18
|
* ivar will always be defined, so stop checkingAaron Patterson2012-08-231-3/+1
|
* initialize instance variables for transactions to remove conditionalsAaron Patterson2012-08-201-8/+6
|
* fix whitespace errorsAaron Patterson2012-08-201-2/+2
|
* Restore state on create when ActiveRecord::RecordInvalid is raisedDave Yeu2012-08-111-1/+1
| | | | This fixes issue #3217.
* Restore the frozen state on rollback. Fixes #6417.Godfrey Chan2012-05-211-1/+3
| | | | | | | | | | | | | | | | | | | | Currently, when saving a frozen record, an exception would be thrown which causes a rollback. However, there is a bug in active record that "defrost" the record as a side effect: >> t = Topic.new => #<Topic id: nil, ...> >> t.freeze => #<Topic id: nil, ...> >> t.save RuntimeError: can't modify a frozen Hash >> t.frozen? => false >> t.save => true This patch fixes the bug by explictly restoring the frozen state on the attributes Hash after every rollback.
* Merge pull request #5535 from markmcspadden/issue_5527_rollbacksAaron Patterson2012-05-161-1/+9
|\ | | | | Allow manual rollbacks in after_save to reset object correctly
| * Allow manual rollbacks in after_save to reset object correctlyMark McSpadden2012-03-211-1/+9
| |
* | Fix transaction state not changing when after record gets commitedHemant Kumar2012-05-091-6/+2
|/
* Remove IdentityMapCarlos Antonio da Silva2012-03-131-2/+0
|
* Remove Array.wrap calls in ActiveRecordRafael Mendonça França2012-01-061-2/+2
|