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

Report information
The Basics
Id:
15635
Status:
resolved
Priority:
Low/Low
Queue:

People
Owner:
Nobody in particular
Requestors:
bbb [...] cpan.org
Cc:
AdminCc:

BugTracker
Severity:
Critical
Broken in:
0.96
Fixed in:
(no value)



Subject: Operation `bool': no method found, argument in overloaded package Class::DBI::Object::Has::Been::Deleted
# uname -a Linux main 2.6.11.12-xenU #1 Thu Aug 4 00:48:08 BST 2005 i686 athlon i386 GNU/Linux # perl -v This is perl, v5.8.5 built for i386-linux-thread-multi Broken in all versions I've tried, including the latest as of this writing: Class-DBI-v3.0.12 It is pretty easy to duplicate this 'bool' error. Just try to access a method that explodes a might_have relationship after performing a delete operation within the same process. It crashes 100% of the time.
EXPLOIT CODE: Music::CD->might_have(liner_notes => LinerNotes => qw/notes/); if ($cd) { if (my $linernotes = $cd->liner_notes) { warn "Deleting linernotes entry..."; $linernotes->delete or die "Delete failed?"; if ($cd->liner_notes) { # <==== XXX - RUNTIME CRASH HERE # BUG TICKET #15635 - Never gets here? warn "Entry successfully deleted."; } else { die "BUG FOUND: Entry still exists?"; } } else { warn "Creating linernotes entry..."; $cd->add_to_liner_notes({ notes => "Testing" }); } }
From: Rob Brown
I'm not sure if this is the most correct way to avoid this runtime crash, but here is a patch that eliminates the problem. -- Rob
--- Class-DBI-v3.0.12/lib/Class/DBI/Relationship/MightHave.pm.BAD 2005-11-08 17:26:29.000000000 -0700 +++ Class-DBI-v3.0.12/lib/Class/DBI/Relationship/MightHave.pm.GOOD 2005-11-08 17:29:40.000000000 -0700 @@ -39,11 +39,14 @@ sub _object_accessor { my $rel = shift; my ($class, $method) = ($rel->class, $rel->accessor); return sub { my $self = shift; my $meta = $class->meta_info($rel->name => $method); my ($f_class, @extra) = ($meta->foreign_class, @{ $meta->args->{import} }); + if(ref($self->{"_${method}_object"}) eq 'Class::DBI::Object::Has::Been::Deleted') { + return undef; + } $self->{"_${method}_object"} ||= $f_class->retrieve($self->id); }; }
From: Rob Brown
fixed offset in patch.
--- Class-DBI-v3.0.12/lib/Class/DBI/Relationship/MightHave.pm.BAD 2005-11-08 17:26:29.000000000 -0700 +++ Class-DBI-v3.0.12/lib/Class/DBI/Relationship/MightHave.pm.GOOD 2005-11-08 17:29:40.000000000 -0700 @@ -39,52 +39,55 @@ sub _object_accessor { my $rel = shift; my ($class, $method) = ($rel->class, $rel->accessor); return sub { my $self = shift; my $meta = $class->meta_info($rel->name => $method); my ($f_class, @extra) = ($meta->foreign_class, @{ $meta->args->{import} }); + if(ref($self->{"_${method}_object"}) eq 'Class::DBI::Object::Has::Been::Deleted') { + return undef; + } $self->{"_${method}_object"} ||= $f_class->retrieve($self->id); }; }
From: Rob Brown
This is the exact same issue explained here: http://www.spanner.org/lists/cdbi/2005/02/23/5b366819.html and complained about by another user: http://forums.slimdevices.com/search.php?searchid=77604 So it's a pretty common problem everyone is getting.
Subject: Failing test case added
Failing test case added
--- Class-DBI-v3.0.12.orig/t/14-might_have.t 2005-12-01 14:31:11.622160624 +0100 +++ Class-DBI-v3.0.12/t/14-might_have.t 2005-12-01 15:45:54.736623632 +0100 @@ -3,7 +3,7 @@ BEGIN { eval "use DBD::SQLite"; - plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 18); + plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 23); } use lib 't/testlib'; @@ -61,4 +61,23 @@ } +Film->create_test_film; +{ + ok my $bt = Film->retrieve('Bad Taste'), "Get Film"; + $bt->blurb("Wibble bar"); + $bt->update; + is $bt->blurb, "Wibble bar", "We can write the info"; + + # Bug #15635: Operation `bool': no method found + $bt->info->delete; + my $blurb = eval { $bt->blurb }; + is $@, '', "Can delete the blurb"; + + is $blurb, undef, "Blurb is now undef"; + + eval { $bt->delete }; + is $@, '', "Can delete the parent object"; +} + +
[BOWMANBS - Thu Dec 1 09:47:00 2005]:
Show quoted text
> Failing test case added
Thanks. Test added, and variation of patch. (I switched to use ->isa rather than ref). New release on its way to CPAN now. Tony


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

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