On 27 Sep 2007, at 00:09, ara.t.howard wrote:

>
> On Sep 26, 2007, at 4:53 PM, Michael Koziarski wrote:
>
>>
>> What do you mean by 'rolling back' model creation.  The transaction
>> should definitely be aborted.  The database should be left as it was
>> before.   If not, you've found a bug for which test cases would be
>> greatly appreciated ;)
>
>
> hey koz-
>
> note that i *am* abusing the api a *little*  (see commented line)
>    begin
>      #ActiveRecord::Base.transaction do
>      ActiveRecord::Base.connection.transaction do

I think you are correct in assuming this is your problem. bits of  
create are wrapped in a transaction (eg so that the callbacks either  
run or don't etc...
sqlite doesn't allow nested transaction, by using  
ActiveRecord::Base.connection.transaction (ie fiddling at the adapter  
level), you're starting the transaction, but not letting rails know  
about it. If you use ActiveRecord::Base.transaction then rails counts  
the transactions opened (so when it's about to do a begin inside  
create it can see it's already in a transaction and thus omit the  
actual begin)

The exception you get isn't your raise - it's the sqlite3 library  
complaining about nested transactions. I don't know sqlite3 much, but  
say in mysql then 'BEGIN' is one of those magic things that  
automatically commits the current transaction, which would explain  
what you see.

In postgres land the path which gets you there is different: the  
first begin executes, rails doesn't know about it. Then you get the  
second begin (from create), which (as per postgresql docs) is a no-op  
(but note the warning you get): you don't actually get the nested  
transaction. rails reaches the end of the transaction it was trying  
to handle in create, since it's not aware of anything else it sends  
commit back to the database: your raise causes no actual rollback  
(you can see rails tried from the warning about there being no  
transaction in progress) because it's too late: the creation of Foo  
has already committed.

Anyway, what I was wondering is why not use  
ActiveRecord::Base.transaction ?

Fred


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to