Skip to content

Commit

Permalink
Proxy the 'unsafe' attribute to the internal ::Versioned storage
Browse files Browse the repository at this point in the history
  • Loading branch information
fgabolde authored and ribasushi committed Apr 14, 2016
1 parent f03d3e5 commit e7dcdf6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion lib/DBIx/Class/Schema/Versioned.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
29 changes: 29 additions & 0 deletions t/94versioning.t
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
Expand Down

0 comments on commit e7dcdf6

Please sign in to comment.