Skip Menu |

This queue is for tickets about the DBIx-Class CPAN distribution.

Report information
The Basics
Id: 53982
Status: resolved
Priority: 0/
Queue: DBIx-Class

People
Owner: ribasushi [...] leporine.io
Requestors: NWELLNHOF [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.08117



Subject: Multi-insert and AutoCommit=0 regression
I just upgraded from DBIx::Class 0.08108 to 0.08115 and I think I found a regression. I'm using AutoCommit=0 and when I try to do create a new row with related rows I get the following error: "DBIx::Class::ResultSet::create(): DBI Exception: DBD::mysql::db begin_work failed: Already in a transaction" Some sample code that triggers the error: use My::Schema; my $schema = My::Schema->connection( $dsn, $user, $pass, { AutoCommit => 0 } ); $schema->resultset('MyResultset')->create({ category => 'test', date => 0, contents => [ { lang => 'en', title => 'Test' } ], }); When I set AutoCommit=1 or when I don't create the related row for "contents" everything works fine.
On Mon Jan 25 13:29:06 2010, NWELLNHOF wrote: Show quoted text
> I just upgraded from DBIx::Class 0.08108 to 0.08115 and I think I found > a regression. I'm using AutoCommit=0 and when I try to do create a new > row with related rows I get the following error: > > "DBIx::Class::ResultSet::create(): DBI Exception: DBD::mysql::db > begin_work failed: Already in a transaction" > > Some sample code that triggers the error: > > use My::Schema; > my $schema = My::Schema->connection( > $dsn, $user, $pass, { AutoCommit => 0 } > ); > $schema->resultset('MyResultset')->create({ > category => 'test', > date => 0, > contents => [ { lang => 'en', title => 'Test' } ], > }); > > When I set AutoCommit=1 or when I don't create the related row for > "contents" everything works fine.
The error message on that could probably be better, but I think what's happening is that multicreate (creating with related stuff as above) does an implicit transaction, and transactions in DBIC are nicer if you have AutoCommit on. From DBIx::Class::Schema: WARNING: If you are connected with AutoCommit => 0 the transaction is considered nested, and you will still need to call "txn_commit" to write your changes when appropriate. You will also want to connect with auto_savepoint => 1 to get partial rollback to work, if the storage driver for your database supports it. Connecting with AutoCommit => 1 is recommended.
On Mon Jan 25 13:29:06 2010, NWELLNHOF wrote: Show quoted text
> I just upgraded from DBIx::Class 0.08108 to 0.08115 and I think I found > a regression. I'm using AutoCommit=0 and when I try to do create a new > row with related rows I get the following error: > > "DBIx::Class::ResultSet::create(): DBI Exception: DBD::mysql::db > begin_work failed: Already in a transaction" > > Some sample code that triggers the error: > > use My::Schema; > my $schema = My::Schema->connection( > $dsn, $user, $pass, { AutoCommit => 0 } > ); > $schema->resultset('MyResultset')->create({ > category => 'test', > date => 0, > contents => [ { lang => 'en', title => 'Test' } ], > }); > > When I set AutoCommit=1 or when I don't create the related row for > "contents" everything works fine.
This is a bug, DBIC should behave correctly when you use AutoCommit=0. It will be fixed in the next release, in the meantime either of the two workarounds will work for you.
On Tue Jan 26 04:10:54 2010, RIBASUSHI wrote: Show quoted text
Thanks for the quick fix. It works for me.