@@ -, +, @@ --- C4/Context.pm | 11 +++++++---- t/db_dependent/Context.t | 5 +---- 2 files changed, 8 insertions(+), 8 deletions(-) --- a/C4/Context.pm +++ a/C4/Context.pm @@ -860,12 +860,15 @@ possibly C<&set_dbh>. sub dbh { my $self = shift; + my $params = shift; my $sth; - if ( defined $db_driver && $db_driver eq 'mysql' && $context->{"dbh"} ) { - return $context->{"dbh"}; - } elsif ( defined $db_driver && defined($context->{"dbh"}) && $context->{"dbh"}->ping()) { - return $context->{"dbh"}; + unless ( $params->{new} ) { + if ( defined $db_driver && $db_driver eq 'mysql' && $context->{"dbh"} ) { + return $context->{"dbh"}; + } elsif ( defined $db_driver && defined($context->{"dbh"}) && $context->{"dbh"}->ping()) { + return $context->{"dbh"}; + } } # No database handle or it died . Create one. --- a/t/db_dependent/Context.t +++ a/t/db_dependent/Context.t @@ -50,9 +50,6 @@ ok($config = $koha->{config}, 'Getting $koha->{config} '); diag "Testing syspref caching."; -my $dbh = C4::Context->dbh; -$dbh->disconnect; - my $module = new Test::MockModule('C4::Context'); $module->mock( '_new_dbh', @@ -64,7 +61,7 @@ $module->mock( ); my $history; -$dbh = C4::Context->dbh; +$dbh = C4::Context->dbh({ new => 1 }); $dbh->{mock_add_resultset} = [ ['value'], ['thing1'] ]; $dbh->{mock_add_resultset} = [ ['value'], ['thing2'] ]; --