Hey All, Am I wrong in thinking that the id and new_record? attributes should be reverted if a transaction is rolled back? They don''t currently revert so the id attribute is left with a value that isn''t actually in the database and new_record? is returning false even though it should be true. Here''s a test demonstrating what I''m talking about: def test_should_reset_id_and_new_record_if_the_transaction_rolls_back topic_count_before_save = Topic.count new_topic = Topic.new( :title => "A new topic", :author_name => "Ben", :author_email_address => "ben@example.com", :written_on => "2003-07-16t15:28:11.2233+01:00", :last_read => "2004-04-15", :bonus_time => "2005-01-30t15:28:00.00+01:00", :content => "Have a nice day", :approved => false) new_record_snapshot = new_topic.new_record? id_present = new_topic.has_attribute?(Topic.primary_key) id_snapshot = new_topic.id Topic.transaction do new_topic.save raise ActiveRecord::Rollback end topic_count_after_save = Topic.count assert_equal topic_count_before_save, topic_count_after_save assert_equal new_record_snapshot, new_topic.new_record?, "The topic should have its old new_record value" assert_equal id_snapshot, new_topic.id, "The topic should have its old id" assert_equal id_present, new_topic.has_attribute? (Topic.primary_key) end Thanks, Jonathan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
You are describing object transactions, Rails used to have support# for those, but it was removed [1] and is currently available as a plugin [2]. [1] http://dev.rubyonrails.org/ticket/5637 [2] http://code.bitsweat.net/svn/object_transactions/ On N, 2007-08-02 at 09:02 -0600, Jonathan Younger wrote:> Hey All, > > Am I wrong in thinking that the id and new_record? attributes should > be reverted if a transaction is rolled back? They don''t currently > revert so the id attribute is left with a value that isn''t actually > in the database and new_record? is returning false even though it > should be true. > > Here''s a test demonstrating what I''m talking about: > > def test_should_reset_id_and_new_record_if_the_transaction_rolls_back > topic_count_before_save = Topic.count > > new_topic = Topic.new( > :title => "A new topic", > :author_name => "Ben", > :author_email_address => "ben@example.com", > :written_on => "2003-07-16t15:28:11.2233+01:00", > :last_read => "2004-04-15", > :bonus_time => "2005-01-30t15:28:00.00+01:00", > :content => "Have a nice day", > :approved => false) > > new_record_snapshot = new_topic.new_record? > id_present = new_topic.has_attribute?(Topic.primary_key) > id_snapshot = new_topic.id > > Topic.transaction do > new_topic.save > raise ActiveRecord::Rollback > end > > topic_count_after_save = Topic.count > > assert_equal topic_count_before_save, topic_count_after_save > assert_equal new_record_snapshot, new_topic.new_record?, "The > topic should have its old new_record value" > assert_equal id_snapshot, new_topic.id, "The topic should have > its old id" > assert_equal id_present, new_topic.has_attribute? > (Topic.primary_key) > end > > Thanks, > > Jonathan > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
This was actually not removed. See http://dev.rubyonrails.org/changeset/5830. I''ve submitted a bug report about this: http://dev.rubyonrails.org/ticket/9105 On Aug 2, 11:27 am, Tarmo Tänav <ta...@itech.ee> wrote:> You are describing object transactions, Rails used to have support# > for those, but it was removed [1] and is currently available > as a plugin [2]. > > [1]http://dev.rubyonrails.org/ticket/5637 > [2]http://code.bitsweat.net/svn/object_transactions/ > > On N, 2007-08-02 at 09:02 -0600, Jonathan Younger wrote: > > > Hey All, > > > Am I wrong in thinking that the id and new_record? attributes should > > be reverted if a transaction is rolled back? They don''t currently > > revert so the id attribute is left with a value that isn''t actually > > in the database and new_record? is returning false even though it > > should be true. > > > Here''s a test demonstrating what I''m talking about: > > > def test_should_reset_id_and_new_record_if_the_transaction_rolls_back > > topic_count_before_save = Topic.count > > > new_topic = Topic.new( > > :title => "A new topic", > > :author_name => "Ben", > > :author_email_address => "b...@example.com", > > :written_on => "2003-07-16t15:28:11.2233+01:00", > > :last_read => "2004-04-15", > > :bonus_time => "2005-01-30t15:28:00.00+01:00", > > :content => "Have a nice day", > > :approved => false) > > > new_record_snapshot = new_topic.new_record? > > id_present = new_topic.has_attribute?(Topic.primary_key) > > id_snapshot = new_topic.id > > > Topic.transaction do > > new_topic.save > > raise ActiveRecord::Rollback > > end > > > topic_count_after_save = Topic.count > > > assert_equal topic_count_before_save, topic_count_after_save > > assert_equal new_record_snapshot, new_topic.new_record?, "The > > topic should have its old new_record value" > > assert_equal id_snapshot, new_topic.id, "The topic should have > > its old id" > > assert_equal id_present, new_topic.has_attribute? > > (Topic.primary_key) > > end > > > Thanks, > > > Jonathan--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
> This was actually not removed. See http://dev.rubyonrails.org/changeset/5830. > I''ve submitted a bug report about this: http://dev.rubyonrails.org/ticket/9105Figuring out what objects were modified in a block is well beyond the scope of what we''re going to fix in 2.0. Rolling back the state from a particular instance is one thing, but extending that is very difficult with AR''s approach to persistence. -- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---