From: Fabrice Gabolde Date: Wed, 13 Apr 2016 13:42:38 +0000 (+0200) Subject: Proxy the 'unsafe' attribute to the internal ::Versioned storage X-Git-Tag: v0.082840~24 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=7150ea46e61ba90c9e8f5ef0f551bd552a1ae42f Proxy the 'unsafe' attribute to the internal ::Versioned storage ( cherry-pick of e7dcdf69f ) --- diff --git a/Changes b/Changes index 24732f7..85d3051 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,8 @@ Revision history for DBIx::Class * Fixes + - Fix use of ::Schema::Versioned combined with a user-supplied + $dbh->{HandleError} (GH#101) - Fix parsing of DSNs containing driver arguments (GH#99) - Work around unreliable $sth->finish() on INSERT ... RETURNING within DBD::Firebird on some compiler/driver combinations (RT#110979) diff --git a/lib/DBIx/Class/Schema/Versioned.pm b/lib/DBIx/Class/Schema/Versioned.pm index 84a5851..c1bbd7b 100644 --- a/lib/DBIx/Class/Schema/Versioned.pm +++ b/lib/DBIx/Class/Schema/Versioned.pm @@ -590,10 +590,15 @@ sub _on_connect { my ($self) = @_; - weaken (my $w_self = $self ); + weaken (my $w_storage = $self->storage ); - $self->{vschema} = DBIx::Class::Version->connect(sub { $w_self->storage->dbh }); - my $conn_attrs = $self->storage->_dbic_connect_attributes || {}; + $self->{vschema} = DBIx::Class::Version->connect( + sub { $w_storage->dbh }, + + # proxy some flags from the main storage + { map { $_ => $w_storage->$_ } qw( unsafe ) }, + ); + my $conn_attrs = $w_storage->_dbic_connect_attributes || {}; my $vtable = $self->{vschema}->resultset('Table'); @@ -602,7 +607,7 @@ sub _on_connect # check for legacy versions table and move to new if exists unless ($self->_source_exists($vtable)) { - my $vtable_compat = DBIx::Class::VersionCompat->connect(sub { $w_self->storage->dbh })->resultset('TableCompat'); + my $vtable_compat = DBIx::Class::VersionCompat->connect(sub { $w_storage->dbh })->resultset('TableCompat'); if ($self->_source_exists($vtable_compat)) { $self->{vschema}->deploy; map { $vtable->new_result({ installed => $_->Installed, version => $_->Version })->insert } $vtable_compat->all; diff --git a/t/94versioning.t b/t/94versioning.t index de45516..0e7b7fd 100644 --- a/t/94versioning.t +++ b/t/94versioning.t @@ -301,6 +301,35 @@ is ), 3, "Expected number of connections at end of script" ; +# Test custom HandleError setting on an in-memory instance +{ + my $custom_handler = sub { die $_[0] }; + + # try to setup a custom error handle without unsafe set -- should + # fail, same behavior as regular Schema + throws_ok { + DBICVersion::Schema->connect( 'dbi:SQLite::memory:', undef, undef, { + HandleError => $custom_handler, + ignore_version => 1, + })->deploy; + } + qr/Refusing clobbering of \{HandleError\} installed on externally supplied DBI handle/, + 'HandleError with unsafe not set causes an exception' + ; + + # now try it with unsafe set -- should work (see RT #113741) + my $s = DBICVersion::Schema->connect( 'dbi:SQLite::memory:', undef, undef, { + unsafe => 1, + HandleError => $custom_handler, + ignore_version => 1, + }); + + $s->deploy; + + is $s->storage->dbh->{HandleError}, $custom_handler, 'Handler properly set on main schema'; + is $s->{vschema}->storage->dbh->{HandleError}, $custom_handler, 'Handler properly set on version subschema'; +} + END { unless ($ENV{DBICTEST_KEEP_VERSIONING_DDL}) { $ddl_dir->rmtree;