Skip Menu |
 

This queue is for tickets about the DBIx-Class CPAN distribution.

Report information
The Basics
Id: 41788
Status: rejected
Priority: 0/
Queue: DBIx-Class

People
Owner: Nobody in particular
Requestors: michael [...] ndrix.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.08010
Fixed in: (no value)

Attachments
0001-Make-dbh_do-reconnect-to-the-database-if-necessary.patch



Subject: Make dbh_do reconnect to the database if necessary
Download (untitled) / with headers
text/plain 239b
When executing a cursor-based search, make sure that the database handle is reconnected. Without this change, a cursor-based search attempted on a disconnected database handle fails (depending on how the DBD handles disconnected handles).
Subject: 0001-Make-dbh_do-reconnect-to-the-database-if-necessary.patch
From 0637f12dace28101c5d26f39b07e034f143d1c0c Mon Sep 17 00:00:00 2001 From: Michael Hendricks <michael@ndrix.org> Date: Wed, 17 Sep 2008 10:34:20 -0600 Subject: [PATCH] Make dbh_do reconnect to the database if necessary When executing a cursor-based search, make sure that the database handle is reconnected. Without this change, a cursor-based search attempted on a disconnected database handle fails (depending on how the DBD handles disconnected handles). Signed-off-by: Michael Hendricks <michael@ndrix.org> --- lib/DBIx/Class/Storage/DBI.pm | 2 +- t/disconnected_search.t | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletions(-) create mode 100644 t/disconnected_search.t diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 806cef8..3239a47 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -588,7 +588,7 @@ sub dbh_do { my $self = shift; my $code = shift; - my $dbh = $self->_dbh; + my $dbh = $self->dbh; return $self->$code($dbh, @_) if $self->{_in_dbh_do} || $self->{transaction_depth}; diff --git a/t/disconnected_search.t b/t/disconnected_search.t new file mode 100644 index 0000000..0c52663 --- /dev/null +++ b/t/disconnected_search.t @@ -0,0 +1,13 @@ +use strict; +use warnings; + +use Test::More tests => 1; +use Test::Warn; +use lib qw(t/lib); +use DBICTest; + +my $schema = DBICTest->init_schema(); +my $dbh = $schema->storage->dbh->disconnect; +warnings_are { + $schema->resultset('Artist')->search( name => 'Chris LeDoux' )->first; +} [], 'searching through a disconnected dbh'; -- 1.5.6
Download (untitled) / with headers
text/plain 335b
I have not reviewed the patch thoroughly, but the swapping of _dbh with dbh brings memories of the following issues: https://rt.cpan.org/Ticket/Display.html?id=32654 https://rt.cpan.org/Ticket/Display.html?id=38186 https://rt.cpan.org/Ticket/Display.html?id=35942 Isn't your patch about to open another hole just like the ones above?
Download (untitled) / with headers
text/plain 975b
On Tue Jan 20 18:42:46 2009, RIBASUSHI wrote: Show quoted text
> I have not reviewed the patch thoroughly, but the swapping of _dbh with > dbh brings memories of the following issues: > > https://rt.cpan.org/Ticket/Display.html?id=32654 > https://rt.cpan.org/Ticket/Display.html?id=38186 > https://rt.cpan.org/Ticket/Display.html?id=35942 > > Isn't your patch about to open another hole just like the ones above?
If this patch does open that hole again, it's a bug in the dbh method and not in the patch. More specifically, it would be a bug in DBIx::Class::Storage::DBI::connected which determines whether we're currently connected to the database or not. If we already have a valid connection to the database, then dbh and _dbh should be identical (minus a little overhead from calling ensure_connected which calls connected). If however, we're not connected to the database, using _dbh causes the query to fail while using dbh will automatically reconnect and the query will succeed.
Download (untitled) / with headers
text/plain 973b
Finally had a chance to look at this patch - it doesn't sound right at all. Consider the following code (without your patch): sub dbh_do { my $self = shift; my $code = shift; my $dbh = $self->_dbh; ... do stuff ... my $exception = $@; if(!$exception) { return $want_array ? @result : $result[0] } $self->throw_exception($exception) if $self->connected; VVVVVVVVVVVVVVV # We were not connected - reconnect and retry, but let any # exception fall right through this time ^^^^^^^^^^^^^^^ $self->_populate_dbh; $self->$code($self->_dbh, @_); } So what you are seeing is not a problem with dbh_do, but possibly an issue with connected(). What database are you using? If it is Oracle - connected was fixed there by the following commit: http://dev.catalyst.perl.org/svnweb/bast/revision/?rev=5479 If you are using a different RDBMS - connected() might need special handling there too. Feel free to reopen this ticket if the above doesn't make sense.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.