[Dbix-class] Overloads in ResultSet and Stacktraces
Aaron Schrab
aaron at schrab.com
Fri Sep 19 16:46:01 BST 2008
I'm working on a Catalyst project that uses DBIx::Class (0.08010) as the
ORM, and the StackTrace plugin. This combination is causing a problem.
In one section of this project I'm using a ResultSet to create a new row
in a table as part of a transaction. In some cases the new row will
violate a unique constraint, so I want to catch those errors and notify
the user. However, the error that I get in $@ isn't due to the
constraint violation.
Instead the error is due to trying to count the number of items in the
ResultSet while in a failed transaction. I've traced this to the
Devel::StackTrace module attempting to stringify the ResultSet. Because
the string conversion operator isn't implemented but the numeric
conversion operator is, the latter is used in place of the former. This
results in trying to do a sql count before the failed transaction is
rolled back.
I've worked around this problem by overloading string conversion to
return a static string, but there may be better ways to avoid this
problem.
Beginning of actual error text:
DBI Exception: DBD::Pg::st execute failed: ERROR: current transaction is aborted, commands ignored until end of transaction block
[for Statement "SELECT COUNT( * ) FROM property me"] at /usr/local/share/perl/5.8.8/DBIx/Class/Schema.pm line 954
Pseudocode:
eval { $schema->txn_do( sub {
$schema->resultset('Property')->create( \%data );
# Violates unique constraint
}) };
if( $@ and $@ =~ /unique constraint/ ) {
# This isn't reached
}
More information about the DBIx-Class
mailing list