Skip Menu |

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

Report information
The Basics
Id: 14798
Status: new
Priority: 0/
Queue: Class-DBI

People
Owner: Nobody in particular
Requestors: moseley [...] hank.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: v3.0.8
Fixed in: (no value)



Subject: Calling Essential twice
I happened to be calling Essential twice on a class. When I did this LAZY POPULATION was not working on columns that were no longer in Essential. Could be an issue when subclassing. DB::Person->columns( Essential => qw/ id first_name last_name content / ); DB::Person->columns( Essential => qw/ id first_name last_name / ); my $item = DB::Person->retrieve( 1 ); print $item->content ? "content found\n" : "sorry, out of luck\n"; Results in: $ perl one_table.pl sorry, out of luck when there is indeed content. CDBI isn't going back to the DB. Comment out either one (or both) of the Essential calls and it works fine. Here's a demo on CDBI 3.0.8: package DB; use base 'Class::DBI::Sweet'; DB->connection('dbi:mysql:test', '', ''); #DB->connection('dbi:Pg:dbname=test2', '', ''); package DB::Person; use base 'DB'; __PACKAGE__->table('person'); __PACKAGE__->columns(All => qw/id first_name last_name role content/); package main; use strict; use warnings; use Template; DB->db_Main->do("DROP TABLE $_") for qw/ person /; DB->db_Main->do(<<""); CREATE TABLE person ( id integer PRIMARY KEY, role integer, first_name text, last_name text, content text ); DB::Person->create( { id => 1, role => 3, first_name => 'Joe', last_name => 'Blow', content => 'This is some content about Joe', }); DB::Person->columns( Essential => qw/ id first_name last_name content / ); DB::Person->columns( Essential => qw/ id first_name last_name / ); my $item = DB::Person->retrieve( 1 ); print $item->content ? "content found\n" : "sorry, out of luck\n";
Date: Thu, 29 Sep 2005 08:20:16 +0100
From: Tony Bowden <tony [...] kasei.com>
To: via RT <bug-Class-DBI [...] rt.cpan.org>
Subject: Re: [cpan #14798] Calling Essential twice
RT-Send-Cc:
On Wed, Sep 28, 2005 at 01:47:05PM -0400, via RT wrote: Show quoted text
> I happened to be calling Essential twice on a class. When I did this > LAZY POPULATION was not working on columns that were no longer in > Essential. Could be an issue when subclassing.
This isn't even Lazy Population being broken - this means that it is impossible to get at the value of content! The test can be reduced to: package DB::Person; use strict; use warnings; use base 'Class::DBI'; __PACKAGE__->table('person'); __PACKAGE__->columns(Essential => qw/id content/); __PACKAGE__->columns(Essential => qw/id/ ); package main; use Test::More tests => 2; my @grps = DB::Person->find_column('content')->groups; is_deeply [@grps], [qw/Essential/], "Content is in essential"; my $essential = grep $_ eq "content", sort DB::Person->_essential; ok $essential, "And essential contains content"; I understand waht's going on - the first call to Essential makes content part of that Group. But the second call to Essential removes it again. This is the effect of leaving it not in any groups - however it still thinks that it's in Essential, so when it comes to load it from the database it says, just load the Essential group and I'll be there. But because it's not there any more, it doesn't get loaded. I'll give some thought to the best way of fixing this. In the meantime the best workaround is to ensure that any columns you implicitly remove from a group are included in another group ('All' isn't really a group). Thanks for the report. Tony