Is this appropriate behavior or a bug?

Consider this code here. It is part of our application's database test script. Its purpose is to hit every rel defined in the database so that we can get an early warning on any class configuration mismatching the state of the database.

# get all the sources
my $sources = $user->result_source->schema->{'source_registrations'};
# grab all the registered sources
foreach my $source (keys %{$sources}) {
 # grab all their relationships
 foreach my $rel (keys %{$sources->{$source}->{'_relationships'}}) {
   eval {
     my $row = $DBH->resultset($source)->single;
     $row->$rel if ($row)
   };
   print "$...@\n" if ($@);
   ok(!$@, "test rel $source->$rel" );
 }
}

Runnign this eventually prints out this message here

DBIx::Class::Relationship::Accessor::__ANON__(): Column dependency_id not loaded or not passed to new() prior to insert() on DB::Schema::cron_task=HASH(0x2fa4940) trying to resolve relationship (maybe you forgot to call ->reload_from_storage to get defaults from the db) at 02_db.t line 40
not ok 563 - test rel cron_task->dependency


Which although I understand the reason for this message, its only relevant when doing a new or insert because the database layer might put a default value in. When doing a select (->single in this case) - The message still throws whenever we attempt to reference an object for which the key is null. Even if it is 100% legitimately null and was just selected as such from the database. Particularly when the relationship was defined as being only a possibility.

__PACKAGE__->might_have( dependency => 'DB::Schema::cron_task', { 'foreign.id' => 'self.dependency_id' } );

Since this table has a conditional relation - there is only a value there if there IS a dependency on the cron task - its inevitable in configuration that there will be null field values in this key field. Any attempt to reference through them used to return undefined, (or nothing when I was playing with null pattern). Now it throws this exception preemptively.

Is this appropriate behavior or is it a bug?

David


PS: The function is 'get_from_storage', not 'reload_from_storage', right

?

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk

Reply via email to