Subject: | Can't use custom HandleError with Schema::Versioned |
I had the following schema class (abbreviated):
<pre>
package My::Schema;
use base 'DBIx::Class::Schema';
__PACKAGE__->load_namespaces;
our $VERSION = 0.007;
...
sub _custom_error_handler {
my ( $dbi_errstr, $dbi_handle ) = @_;
# munge exception and rethrow
}
sub connection {
# override DBIC's connection method to add custom exception
# handling
my ( $self, $dsn, $user, $password, $options, @rest ) = @_;
# not sure cloning is really required
my $options_clone = { %{ $options // {} } };
# see https://metacpan.org/pod/DBIx::Class::Storage::DBI#unsafe
$options_clone->{HandleError} = \&_custom_error_handler;
$options_clone->{unsafe} = 1;
$self->SUPER::connection( $dsn, $user, $password, $options_clone, @rest );
}
</pre>
This works fine. However, if I switch to DBIx::Class::Schema::Versioned, I get the following error when calling $schema->deploy({ add_drop_table => 1 }):
<pre>
DBIx::Class::Storage::DBI::catch {...} (): DBI Connection failed: DBIx::Class::Storage::DBI::try {...} (): Refusing clobbering of {HandleError} installed on externally supplied DBI handle DBI::db=HASH(0xc3ee6f0). Either remove the handler or use the 'unsafe' attribute. at t/lib/BasicFixture.pm line 47 at t/lib/BasicFixture.pm line 47
</pre>
This occurs right after the actual deploy, since the tables have been created, but no code after deploy() has been called. It sounds like a second dbh is created from the connection info gathered from the original, but by that time "unsafe" has been lost.