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-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e7dcdf69fd96a9a50696607171defaf03075592f;p=dbsrgits%2FDBIx-Class.git Proxy the 'unsafe' attribute to the internal ::Versioned storage --- diff --git a/Changes b/Changes index 9f8ec85..f71dec5 100644 --- a/Changes +++ b/Changes @@ -51,6 +51,8 @@ Revision history for DBIx::Class - Fix spurious ROLLBACK statements when a TxnScopeGuard fails a commit of a transaction with deferred FK checks: a guard is now inactivated immediately before the commit is attempted (RT#107159) + - Fix use of ::Schema::Versioned combined with a user-supplied + $dbh->{HandleError} (GH#101) - Fix spurious warning on MSSQL cursor invalidation retries (RT#102166) - Fix parsing of DSNs containing driver arguments (GH#99) - Work around unreliable $sth->finish() on INSERT ... RETURNING within diff --git a/lib/DBIx/Class/Schema/Versioned.pm b/lib/DBIx/Class/Schema/Versioned.pm index eb4fe65..013cbc4 100644 --- a/lib/DBIx/Class/Schema/Versioned.pm +++ b/lib/DBIx/Class/Schema/Versioned.pm @@ -591,7 +591,12 @@ sub _on_connect weaken (my $w_storage = $self->storage ); - $self->{vschema} = DBIx::Class::Version->connect(sub { $w_storage->dbh }); + $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'); diff --git a/t/94versioning.t b/t/94versioning.t index ab9d261..117f02a 100644 --- a/t/94versioning.t +++ b/t/94versioning.t @@ -281,6 +281,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 { rm_rf $ddl_dir unless $ENV{DBICTEST_KEEP_VERSIONING_DDL}; }