# ActiveSupport::TestCase fails to roll back?

**URL:** <https://www.ruby-forum.com/t/activesupport-testcase-fails-to-roll-back/193294>\
**Category:** Rails\
**Created:** [August 15, 2010, 12:27am UTC](https://www.ruby-forum.com/t/activesupport-testcase-fails-to-roll-back/193294 "2010-08-15T00:27:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fearless\_fool](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@fearless\_fool](https://www.ruby-forum.com/u/fearless_fool)\
**Post date:** [August 15, 2010, 12:27am UTC](https://www.ruby-forum.com/t/activesupport-testcase-fails-to-roll-back/193294/1 "2010-08-15T00:27:04Z")

</div>

A simple test case that ran properly under 2.3 blows up in 3.0RC2 with  
the error:

Exception raised:  
\<#\<ActiveRecord::StatementInvalid: Mysql::Error: SAVEPOINT  
active\_record\_1 does not exist: ROLLBACK TO SAVEPOINT active\_record\_1\>\>.

People have reporte this error where there are concurrent processes, but  
mine is single process. Can someone teach me how to find out if this  
has been reported as a bug, and if not, what additional info / test case  
I can provide?

Thanks.

- ff

Additional info:

One possibly interesting thing: I can explicitly turn OFF transactional  
fixtures in test\_helper.rb with:  
self.use\_transactional\_fixtures = false  
… at which point the rollback error goes away, but my tests fail  
because my tests expect the database to be empty, but it’s not. (I  
thought that was the expected behavior of setting transactional fixtures  
to true, not false – no matter).

My code (\>\>\> marks the line that got the error):

def test\_basic\_page\_cache  
assert\_nothing\_raised {@cache =  
PageCacheStore.find\_or\_create\_page\_cache(:web\_page\_cache)}

> > > assert\_nothing\_raised {@cache.write(“today”, “Monday”)}  
> > > assert(@cache.read(“today”) == “Monday”)  
> > > assert\_nil(@cache.read(“city”))  
> > > assert\_nil(@cache.fetch(“city”))

```
assert_nothing_raised do
  @cache.fetch("city") do
    "Ducksberg"
  end
end

```

end

The test log:

SQL (0.2ms) BEGIN  
SQL (0.6ms) SHOW TABLES  
SQL (63.7ms) CREATE TABLE `web_page_caches` (`id` int(11) DEFAULT  
NULL auto\_increment PRIMARY KEY, `key` varchar(255), `value`  
varchar(255), `expires_at` datetime) ENGINE=InnoDB  
SQL (0.4ms) SHOW KEYS FROM `web_page_caches`  
SQL (163.1ms) CREATE UNIQUE INDEX `index_on_key` ON `web_page_caches`  
(`key`)  
SQL (0.4ms) SHOW TABLES  
WebPageCache Load (0.2ms) SELECT `web_page_caches`.\* FROM  
`web_page_caches` WHERE (`web_page_caches`.`key` = ‘today’) LIMIT 1  
SQL (0.2ms) SAVEPOINT active\_record\_1  
SQL (0.8ms) describe `web_page_caches`  
SQL (0.5ms) INSERT INTO `web_page_caches` (`expires_at`, `key`,  
`value`) VALUES (NULL, ‘today’, ‘Monday’)  
SQL (0.2ms) RELEASE SAVEPOINT active\_record\_1  
Mysql::Error: SAVEPOINT active\_record\_1 does not exist: RELEASE  
SAVEPOINT active\_record\_1  
SQL (0.1ms) ROLLBACK TO SAVEPOINT active\_record\_1  
Mysql::Error: SAVEPOINT active\_record\_1 does not exist: ROLLBACK TO  
SAVEPOINT active\_record\_1  
SQL (0.1ms) ROLLBACK

My config:

bash$ rake about  
About your application’s environment  
Ruby version 1.9.2 (x86\_64-darwin10.4.0)  
RubyGems version 1.3.7  
Rack version 1.2  
Rails version 3.0.0.rc  
Active Record version 3.0.0.rc  
Action Pack version 3.0.0.rc  
Active Resource version 3.0.0.rc  
Action Mailer version 3.0.0.rc  
Active Support version 3.0.0.rc  
Environment development

---

<div class="post-metadata">

**Author:** ![fearless\_fool](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@fearless\_fool](https://www.ruby-forum.com/u/fearless_fool)\
**Post date:** [August 15, 2010, 12:45am UTC](https://www.ruby-forum.com/t/activesupport-testcase-fails-to-roll-back/193294/2 "2010-08-15T00:45:22Z")

</div>

Update: Does ROLLBACK undo the creation of new tables?

I ask because find\_or\_create\_page\_cache(:name) has the effect of  
creating an AR table named “name” if it doesn’t already exist. This  
appears to confuse the rollback mechanism under certain circumstances in  
Rails 3.0RC2, but I never had this problem in Rails 2.8.

- ff

---

<div class="post-metadata">

**Author:** ![fearless\_fool](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@fearless\_fool](https://www.ruby-forum.com/u/fearless_fool)\
**Post date:** [August 15, 2010, 1:14pm UTC](https://www.ruby-forum.com/t/activesupport-testcase-fails-to-roll-back/193294/3 "2010-08-15T13:14:40Z")

</div>

On Aug 14, 11:45 pm, Fearless F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Update: Does ROLLBACK undo the creation of new tables?
> 
> I ask because find\_or\_create\_page\_cache(:name) has the effect of  
> creating an AR table named “name” if it doesn’t already exist. This  
> appears to confuse the rollback mechanism under certain circumstances in  
> Rails 3.0RC2, but I never had this problem in Rails 2.8.

Assuming you’re using mysql, this won’t work - mysql doesn’t support  
rolling back statements that change the schema (adding tables, columns  
etc…), executing any such statement implicitly commits the current  
transaction

Fred

---

<div class="post-metadata">

**Author:** ![fearless\_fool](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@fearless\_fool](https://www.ruby-forum.com/u/fearless_fool)\
**Post date:** [August 15, 2010, 6:17pm UTC](https://www.ruby-forum.com/t/activesupport-testcase-fails-to-roll-back/193294/4 "2010-08-15T18:17:45Z")

</div>

> Yet another piece of MySQL suckage. Assuming you’re using MySQL, drop  
> it in favor of Postgres…
> 
> > Fred
> 
> Best,  
> –Â  
> Marnen Laibow-Koser

MySQL 6 will introduce two new database engines which should replace  
innodb called Maria and Falcon which house this feature, along with  
recoverability features.

---

<div class="post-metadata">

**Author:** ![fearless\_fool](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@fearless\_fool](https://www.ruby-forum.com/u/fearless_fool)\
**Post date:** [August 15, 2010, 6:54pm UTC](https://www.ruby-forum.com/t/activesupport-testcase-fails-to-roll-back/193294/5 "2010-08-15T18:54:10Z")

</div>

On Sun, 2010-08-15 at 18:17 +0200, Alpha B. wrote:

> MySQL 6 will introduce two new database engines which should replace  
> innodb called Maria and Falcon which house this feature, along with  
> recoverability features.

* * *

it will be interesting to see what kind of licensing restrictions come  
with any enhancements from Oracle. They did sort of give notice to the  
open source world that even though Ellison has spoken against software  
patents, he will aggressively use them to generate revenue - Sun would  
never have gone down that path. I think people should think long and  
hard about any more MySQL development.

Craig

–  
This message has been scanned for viruses and  
dangerous content by MailScanner, and is  
believed to be clean.

---

<div class="post-metadata">

**Author:** ![fearless\_fool](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@fearless\_fool](https://www.ruby-forum.com/u/fearless_fool)\
**Post date:** [August 15, 2010, 5:00pm UTC](https://www.ruby-forum.com/t/activesupport-testcase-fails-to-roll-back/193294/6 "2010-08-15T17:00:49Z")

</div>

Frederick C. wrote:

> On Aug 14, 11:45ï¿½pm, Fearless F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Update: Does ROLLBACK undo the creation of new tables?
> > 
> > I ask because find\_or\_create\_page\_cache(:name) has the effect of  
> > creating an AR table named “name” if it doesn’t already exist. ï¿½This  
> > appears to confuse the rollback mechanism under certain circumstances in  
> > Rails 3.0RC2, but I never had this problem in Rails 2.8.
> 
> Assuming you’re using mysql, this won’t work - mysql doesn’t support  
> rolling back statements that change the schema (adding tables, columns  
> etc…), executing any such statement implicitly commits the current  
> transaction

Yet another piece of MySQL suckage. Assuming you’re using MySQL, drop  
it in favor of Postgres…

> Fred

Best,  
–Â  
Marnen Laibow-Koser

> **[marnen.org: Homepage of Marnen Laibow-Koser](https://marnen.org/)**

[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Sent from my iPhone
